unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Fix python exception object string repr
@ 2021-11-06 11:02 Floris Bruynooghe
  2021-11-06 11:02 ` [PATCH] Fix error message when using notmuch_status_to_string Floris Bruynooghe
  0 siblings, 1 reply; 2+ messages in thread
From: Floris Bruynooghe @ 2021-11-06 11:02 UTC (permalink / raw)
  To: notmuch


This fixes a bug in the exception class which would produce
unprintable exceptions because it was not converting an error
code correctly to a string.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] Fix error message when using notmuch_status_to_string
  2021-11-06 11:02 Fix python exception object string repr Floris Bruynooghe
@ 2021-11-06 11:02 ` Floris Bruynooghe
  0 siblings, 0 replies; 2+ messages in thread
From: Floris Bruynooghe @ 2021-11-06 11:02 UTC (permalink / raw)
  To: notmuch

The python exception class was incorrectly loading the error message
which resulted in unprintable exception objects.
---
 bindings/python-cffi/notmuch2/_errors.py  | 3 ++-
 bindings/python-cffi/tests/test_errors.py | 8 ++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 bindings/python-cffi/tests/test_errors.py

diff --git a/bindings/python-cffi/notmuch2/_errors.py b/bindings/python-cffi/notmuch2/_errors.py
index f55cc96b..17c3ad9c 100644
--- a/bindings/python-cffi/notmuch2/_errors.py
+++ b/bindings/python-cffi/notmuch2/_errors.py
@@ -83,7 +83,8 @@ class NotmuchError(Exception):
         if self.message:
             return self.message
         elif self.status:
-            return capi.lib.notmuch_status_to_string(self.status)
+            char_str = capi.lib.notmuch_status_to_string(self.status)
+            return capi.ffi.string(char_str).decode(errors='replace')
         else:
             return 'Unknown error'
 
diff --git a/bindings/python-cffi/tests/test_errors.py b/bindings/python-cffi/tests/test_errors.py
new file mode 100644
index 00000000..c2519f86
--- /dev/null
+++ b/bindings/python-cffi/tests/test_errors.py
@@ -0,0 +1,8 @@
+from notmuch2 import _capi as capi
+from notmuch2 import _errors as errors
+
+def test_status_no_message():
+    exc = errors.NotmuchError(capi.lib.NOTMUCH_STATUS_PATH_ERROR)
+    assert exc.status == capi.lib.NOTMUCH_STATUS_PATH_ERROR
+    assert exc.message is None
+    assert str(exc) == 'Path supplied is illegal for this function'
-- 
2.33.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-06 11:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-06 11:02 Fix python exception object string repr Floris Bruynooghe
2021-11-06 11:02 ` [PATCH] Fix error message when using notmuch_status_to_string Floris Bruynooghe

Code repositories for project(s) associated with this inbox:

	notmuch.git.git (no URL configured)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).