Skip to content
Myr

✨ Handle `KeyboardInterrupt` separately from other exceptions (#1039)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Patrick Arminio · committed by GitHub · parent e31fc57 · Browse files · 2 files+16 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Diff stats

2 files+16 added−1 removed

  • tests:+13 added−0 removed
  • other:+3 added−1 removed

2 files+16 added−1 removed

modified:tests/test_exit_errors.py+13 added
17 unmodified lines
18 result = runner.invoke(app)19 assert result.exit_code == 1202122def test_keyboardinterrupt():23 # Mainly for coverage/completeness24 app = typer.Typer()2526 @app.command()27 def main():28 raise KeyboardInterrupt()2930 result = runner.invoke(app)31 assert result.exit_code == 13032 assert result.stdout == ""333435def test_oserror():36 # Mainly for coverage/completeness37 app = typer.Typer()38
20 unmodified lines
modified:typer/core.py+3 added-1 removed
203 unmodified lines
204 # chained commands which all returned `None` -- so it's not205 # even always obvious that `rv` indicates success/failure206 # by its truthiness/falsiness207 ctx.exit()208 except (EOFError, KeyboardInterrupt) as e:208 except EOFError as e:209 click.echo(file=sys.stderr)210 raise click.Abort() from e211 except KeyboardInterrupt as e:212 raise click.exceptions.Exit(130) from e213 except click.ClickException as e:214 if not standalone_mode:215 raise216 # Typer override
536 unmodified lines