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
When click exits, it raises a RuntimeError even when everything worked ok. Hence, if I wrap a call to a click command inside a try/except, this will be picked up as an exception even though nothing went wrong.
This creates a problem with ipython, which catches all exceptions and does some custom handling of them. What happens appears to be: ipython executes the code, click raises the RuntimeError, ipython catches it but because there's no actual error message or traceback, ipython seems to get confused and generates even more exceptions.
Is there a reason why click raises an exception even when the program ran ok and code == 0? I changed the click behaviour very slightly to no longer do so and it fixes this completely, but I'm guessing there's a reason click doesn't do this already?
Command executes ok (even with arguments, like hello(["--count", 3]) but will afterwards produce the following exception (see full traceback):
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
Traceback (most recent call last):
File "/Users/antony_milne/miniconda3/envs/spaceflights/lib/python3.8/site-packages/click/core.py", line 1065, in main
ctx.exit()
File "/Users/antony_milne/miniconda3/envs/spaceflights/lib/python3.8/site-packages/click/core.py", line 687, in exit
raise Exit(code)
click.exceptions.Exit: 0
Note: that ipython -m hello works ok, as does the above flow when using python. It's only when running an interactive ipython session that click's RuntimeError is problematic.
What should happen
No traceback from ipython.
Environment
Python version: 3.8.13
Click version: 8.1.2
The text was updated successfully, but these errors were encountered:
ok, but is it normal for a program to exit by raising an exception even when nothing went wrong? Is there no other way for click to exit in the case of code == 0 in a way that wouldn't get caught by except?
Thanks for the tip about standalone_mode - I wasn't aware of that.
When click exits, it raises a RuntimeError even when everything worked ok. Hence, if I wrap a call to a click command inside a
try/except
, this will be picked up as an exception even though nothing went wrong.This creates a problem with ipython, which catches all exceptions and does some custom handling of them. What happens appears to be: ipython executes the code, click raises the
RuntimeError
, ipython catches it but because there's no actual error message or traceback, ipython seems to get confused and generates even more exceptions.Is there a reason why click raises an exception even when the program ran ok and
code == 0
? I changed the click behaviour very slightly to no longer do so and it fixes this completely, but I'm guessing there's a reason click doesn't do this already?Steps to reproduce
ipython
from hello import hello; hello()
hello(["--count", 3])
but will afterwards produce the following exception (see full traceback):Note: that
ipython -m hello
works ok, as does the above flow when usingpython
. It's only when running an interactive ipython session that click's RuntimeError is problematic.What should happen
No traceback from ipython.
Environment
The text was updated successfully, but these errors were encountered: