Skip to content

Commit

Permalink
Do not suppress EOFError/KeyboardInterrupt when standalone is disabled
Browse files Browse the repository at this point in the history
Raise Abort() exception in a chain with the original exception.
  • Loading branch information
atugushev committed Oct 17, 2022
1 parent 2b60d81 commit 68bed2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,9 +1063,9 @@ def main(
# even always obvious that `rv` indicates success/failure
# by its truthiness/falsiness
ctx.exit()
except (EOFError, KeyboardInterrupt):
except (EOFError, KeyboardInterrupt) as e:
echo(file=sys.stderr)
raise Abort() from None
raise Abort() from e
except ClickException as e:
if not standalone_mode:
raise
Expand Down
12 changes: 12 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,15 @@ def command2(e):

runner.invoke(group, ["command1"])
assert opt_prefixes == {"-", "--", "~", "+"}


@pytest.mark.parametrize("exc", (EOFError, KeyboardInterrupt))
def test_abort_exceptions_with_disabled_standalone_mode(runner, exc):
@click.command()
def cli():
raise exc("catch me!")

rv = runner.invoke(cli, standalone_mode=False)
assert rv.exit_code == 1
assert isinstance(rv.exception.__cause__, exc)
assert rv.exception.__cause__.args == ("catch me!",)

0 comments on commit 68bed2a

Please sign in to comment.