Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error_trace to string representation of an Error #648

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Unreleased
about necessary migration steps.
- Configured DB API interface attribute ``threadsafety = 1``, which signals
"Threads may share the module, but not connections."
- Added ``error_trace`` to string representation of an Error to relay
server stacktraces into exception messages.

.. _Migrate from crate.client to sqlalchemy-cratedb: https://cratedb.com/docs/sqlalchemy-cratedb/migrate-from-crate-client.html
.. _sqlalchemy-cratedb: https://pypi.org/project/sqlalchemy-cratedb/
Expand Down
5 changes: 5 additions & 0 deletions src/crate/client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
super(Error, self).__init__(msg)
self.error_trace = error_trace

def __str__(self):
if self.error_trace is None:
return super().__str__()
return "\n".join([super().__str__(), str(self.error_trace)])

Check warning on line 36 in src/crate/client/exceptions.py

View check run for this annotation

Codecov / codecov/patch

src/crate/client/exceptions.py#L36

Added line #L36 was not covered by tests


class Warning(Exception):
pass
Expand Down
14 changes: 14 additions & 0 deletions src/crate/client/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import unittest

from crate.client import Error


class ErrorTestCase(unittest.TestCase):

def test_error_with_msg(self):
err = Error("foo")
self.assertEqual(str(err), "foo")

def test_error_with_error_trace(self):
err = Error("foo", error_trace="### TRACE ###")
self.assertEqual(str(err), "foo\n### TRACE ###")