diff --git a/tests/test_exit_errors.py b/tests/test_exit_errors.py index 598308b1d1..344c3b5733 100644 --- a/tests/test_exit_errors.py +++ b/tests/test_exit_errors.py @@ -18,6 +18,17 @@ def main(): result = runner.invoke(app) assert result.exit_code == 1 +def test_keyboardinterrupt(): + # Mainly for coverage/completeness + app = typer.Typer() + + @app.command() + def main(): + raise KeyboardInterrupt() + + result = runner.invoke(app) + assert result.exit_code == 130 + assert result.stdout == "" def test_oserror(): # Mainly for coverage/completeness diff --git a/typer/core.py b/typer/core.py index 4b2d3ba3be..aef3dabe49 100644 --- a/typer/core.py +++ b/typer/core.py @@ -209,7 +209,7 @@ def _main( click.echo(file=sys.stderr) raise click.Abort() from e except KeyboardInterrupt as e: - raise click.exceptions.Exit() from e + raise click.exceptions.Exit(130) from e except click.ClickException as e: if not standalone_mode: raise