PySnooper
PySnooper copied to clipboard
Incorrect "Call ended by exception" when using finally blocks
The method for testing if a call ended with an exception is not quite accurate. Here's an example:
import pysnooper
@pysnooper.snoop()
def foo():
try:
return None
finally:
pass
foo()
22:07:00.954045 call 5 def foo():
22:07:00.954555 line 6 try:
22:07:00.954637 line 7 return None
22:07:00.956724 line 9 pass
Call ended by exception
I don't know of any easy reliable way to tell the difference between returning None and raising an exception inside a try/finally. For now I keep track of whether a call has raised an exception at all, and if it hasn't (like above) I know it's definitely a return. If it has, I simply don't know: https://github.com/alexmojaki/snoop/blob/a93925011365099abb8f77315060093a1efed29b/snoop/formatting.py#L271
On a related note, I started a discussion about truncating exception messages here which you may want to follow.
Thanks for reporting this. Right now I think it's a small enough issue that I can ignore it.