cknd / stackprinter

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

Add support for KeyboardInterrupt in REPL #5

Closed YashSinha1996 closed 5 years ago

YashSinha1996 commented 5 years ago

On keyboard interrupt in REPL, it raises the following stacktrace:

Error in sys.excepthook:
Traceback (most recent call last):
  File "/datadrive/product_type_article/venv/lib/python3.7/site-packages/stackprinter/__init__.py", line 245, in hook
    show(args, **kwargs)
  File "/datadrive/product_type_article/venv/lib/python3.7/site-packages/stackprinter/__init__.py", line 23, in show_or_format
    return f(thing, *args, **kwargs)
  File "/datadrive/product_type_article/venv/lib/python3.7/site-packages/stackprinter/__init__.py", line 163, in show
    print(format(thing, **kwargs), file=file)
  File "/datadrive/product_type_article/venv/lib/python3.7/site-packages/stackprinter/__init__.py", line 23, in show_or_format
    return f(thing, *args, **kwargs)
  File "/datadrive/product_type_article/venv/lib/python3.7/site-packages/stackprinter/__init__.py", line 142, in format
    "a frame or a thread object." % repr(thing))
ValueError: Can't format (<class 'KeyboardInterrupt'>, KeyboardInterrupt(), None). Expected an exception instance, sys.exc_info() tuple,a frame or a thread object.

Original exception was:
KeyboardInterrupt

I would love to contribute to help out, but I am not sure what the behaviour should be in this case?

Awesome project BTW.

cknd commented 5 years ago

Thanks! Can you post your python version? I can't reproduce it on 3.5.2. Though I get a similar problem on syntax errors in the REPL and might have an idea to fix both. Looks like the traceback is None for that exception, which should be easy to deal with (= just print the exception)

cknd commented 5 years ago

https://github.com/cknd/stackprinter/pull/6

YashSinha1996 commented 5 years ago

Hey @cknd I am on 3.7.2.

cknd commented 5 years ago

This should be fixed on the latest release (0.2.0). Can you do a pip install -U stackprinter to confirm?

YashSinha1996 commented 5 years ago

Hey @cknd thanks a lot. Fixed!