cknd / stackprinter

Debugging-friendly exceptions for Python
MIT License
1.28k stars 37 forks source link

Gracefully handle exception being "(None, None, None)" #35

Closed Delgan closed 4 years ago

Delgan commented 4 years ago

Hi!

The built-in traceback module handles (None, None, None) tuple (returned if sys.exc_info() is called outside the context of an exception) without raising an error:

import traceback

traceback.print_exception(None, None, None)
# 'NoneType: None'

Using stackprinter, however:

import stackprinter

stackprinter.format((None, None, None))
# ValueError: Can't format (None, None, None). Expected an exception instance, sys.exc_info() tuple,a frame or a thread object.

You may argue that formatting such exception is pretty useless... You're right. :smile:

Still, in my situation it happens that the exception tuple looks more like (TypeError, None, None) (I'll save you the details, but it happens if the error value can't be serialized, then it is replaced by None by default). In such case, it would be nice to format the error like TypeError: None for example instead of raising a ValueError. That would be useful so that user could format any exception-tuple without having to check for edge cases like that.

alexmojaki commented 4 years ago

I'm curious about the fact that you're choosing stackprinter over better-exceptions :eyes:

Delgan commented 4 years ago

@alexmojaki Well, both are great libraries in my opinion. :smile:

I got a bug report from an user. It seems that a library I developed is not fully compatible with stackprinter due to edge case like this one. I think it would be better if it could work transparently for the user.

cknd commented 4 years ago

Hi! I agree, the closer to the builtin traceback behavior the better. I'll check out your PR (thanks!) as soon as I get back to my computer

Delgan commented 4 years ago

Fixed by #36. Thanks for the merge @cknd. :+1:

cknd commented 3 years ago

this is now released in 0.2.5

cknd commented 3 years ago

cc @JulianOrteil ☝️

JulianOrteil commented 3 years ago

Saw this, thank you. Already updated my installation 👍