]> git.notmuchmail.org Git - notmuch/commitdiff
Fix error message when using notmuch_status_to_string
authorFloris Bruynooghe <flub@devork.be>
Sat, 6 Nov 2021 11:02:37 +0000 (12:02 +0100)
committerDavid Bremner <david@tethera.net>
Sun, 5 Dec 2021 12:53:39 +0000 (08:53 -0400)
The python exception class was incorrectly loading the error message
which resulted in unprintable exception objects.

bindings/python-cffi/notmuch2/_errors.py
bindings/python-cffi/tests/test_errors.py [new file with mode: 0644]

index f55cc96b53bf44ba69cbbd0b5774626fc8006632..17c3ad9cc39af7cf565f66aae9570bcba22a8f9c 100644 (file)
@@ -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 (file)
index 0000000..c2519f8
--- /dev/null
@@ -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'