You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
I would like to hook traceback printing to use better_exceptions #10422
The better-exceptions package makes very pretty tracebacks with a lot of useful information in them. It would be nice if ipython could be hooked so that it used that package to print out exception tracebacks.
It doesn't look like the set_custom_exc is quite the right thing, partly because it expects that you will want to only handle a small subset of exception types. Also, it has a tb_offset argument that isn't terribly well documented.
I agree that it would be good to have an official hook for this, but if you want to experiment with it in the meantime, try replacing get_ipython()._showtraceback.
That doesn't work because by the time the data gets to _showtraceback, ipython has already eaten the traceback and made strings out of it.
The better_exceptions package goes through the traceback and does variable lookups and a whole bunch of stuff. So it needs the raw stack data, not the strings that result from processing that data.
@Omnifarious if you are motivated the exception handling could need some love, we already have multiple mode (using xmode). If you want to make it more pluggable to allow better switching that would be great. There is also a long standing issue (somewhere), to make tracebacks more structured so that we could provide richer representations in particular in the notebook.
Just for future reference, it's generally better to put scripts (really, anything more than example code) on GitHub Gist, then just link to the gist here. It's makes the code easier to maintain and discover, and helps to keep the comments in these conversations short and tidy.
Reacted by Eric Hopper, Iblis Lin and Chiu-Hsiang Hsu
Activity
takluyver commentedon Mar 31, 2017
I agree that it would be good to have an official hook for this, but if you want to experiment with it in the meantime, try replacing
get_ipython()._showtraceback.Omnifarious commentedon Mar 31, 2017
That doesn't work because by the time the data gets to _showtraceback, ipython has already eaten the traceback and made strings out of it.
The better_exceptions package goes through the traceback and does variable lookups and a whole bunch of stuff. So it needs the raw stack data, not the strings that result from processing that data.
takluyver commentedon Mar 31, 2017
Right. Maybe override
showtraceback?Omnifarious commentedon Mar 31, 2017
Yes, that appears to work. Though that function takes a lot of extra arguments that I don't know what mean.
Omnifarious commentedon Mar 31, 2017
Here's an ipython startup file that does the trick:
Carreau commentedon Apr 3, 2017
@Omnifarious if you are motivated the exception handling could need some love, we already have multiple mode (using
xmode). If you want to make it more pluggable to allow better switching that would be great. There is also a long standing issue (somewhere), to make tracebacks more structured so that we could provide richer representations in particular in the notebook.Omnifarious commentedon Apr 11, 2017
@Carreau - I don't think that I'm motivated enough to do that at this time. :-)
But, I realized that the above snippet was sub-optimal, and I wanted to add a better version, and per your suggestion I've put it in a gist:
https://gist.github.com/Omnifarious/bfe19f07fd21e582591ee632ddca47ee
carlsmith commentedon Apr 12, 2017
Just for future reference, it's generally better to put scripts (really, anything more than example code) on GitHub Gist, then just link to the gist here. It's makes the code easier to maintain and discover, and helps to keep the comments in these conversations short and tidy.