[Libguestfs] [PATCH nbdkit] python: Print readable tracebacks

Nir Soffer nirsof at gmail.com
Sat Nov 23 03:06:41 UTC 2019


We used traceback.format_exception, returning traceback lines. Join the
lines to make the tracebacks more readable.

Here is an example traceback:

$ ./nbdkit -f -v python tests/python-exception.py
...
nbdkit: debug: python: config_complete
nbdkit: error: tests/python-exception.py: config_complete: error: Traceback (most recent call last):
   File "tests/python-exception.py", line 51, in config_complete
    raise RuntimeError("this is the test string")
 RuntimeError: this is the test string
---
 plugins/python/python.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/plugins/python/python.c b/plugins/python/python.c
index 148097f..71fa2e3 100644
--- a/plugins/python/python.c
+++ b/plugins/python/python.c
@@ -167,7 +167,7 @@ print_python_traceback (const char *callback,
                                      type, error, traceback, NULL);
   if (rv == NULL)
     return -1;
-  traceback_str = PyObject_Str (rv);
+  traceback_str = PyUnicode_Join (NULL, rv);
   Py_DECREF (rv);
   traceback_cstr = python_to_string (traceback_str);
   if (traceback_cstr == NULL) {
-- 
2.21.0





More information about the Libguestfs mailing list