Nir Soffer
2019-Nov-23 03:06 UTC
[Libguestfs] [PATCH nbdkit] python: Print readable tracebacks
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
Richard W.M. Jones
2019-Nov-23 13:21 UTC
Re: [Libguestfs] [PATCH nbdkit] python: Print readable tracebacks
On Sat, Nov 23, 2019 at 05:06:41AM +0200, Nir Soffer wrote:> 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) {ACK and pushed, thanks. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Apparently Analagous Threads
- [PATCH nbdkit] python: Try harder to print the full traceback on error.
- Re: [PATCH nbdkit] python: Try harder to print the full traceback on error.
- [PATCH nbdkit] python: Drop support for Python 2.
- [PATCH nbdkit] python: Drop support for Python 2.
- Re: [PATCH nbdkit] python: Turn python exceptions into nbdkit errors properly.