Skip to content

Commit

Permalink
Fix the exit code when there happens to be an unhandled exception (#1389
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ofek authored Apr 14, 2024
1 parent 7569838 commit 675ab25
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/history/hatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- De-select Ruff rule `E501` for the `fmt` command by default since it conflicts with the formatter
- Fix colored output from build targets on the first run (build environment creation status indicator issue)
- Set the `packaging` dependency version as `>=23.2` to avoid its URL validation which can conflict with context formatting
- Fix the exit code when there happens to be an unhandled exception

## [1.9.4](https://github.com/pypa/hatch/releases/tag/hatch-v1.9.4) - 2024-03-12 ## {: #hatch-v1.9.4 }

Expand Down
4 changes: 1 addition & 3 deletions src/hatch/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import sys

if __name__ == '__main__':
from hatch.cli import main

sys.exit(main())
main()
6 changes: 4 additions & 2 deletions src/hatch/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,13 @@ def hatch(ctx: click.Context, env_name, project, verbose, quiet, color, interact

def main(): # no cov
try:
return hatch(prog_name='hatch', windows_expand_args=False)
hatch(prog_name='hatch', windows_expand_args=False)
except Exception: # noqa: BLE001
import sys

from rich.console import Console

console = Console()
hatch_debug = os.getenv('HATCH_DEBUG') in {'1', 'true'}
console.print_exception(suppress=[click], show_locals=hatch_debug)
return 1
sys.exit(1)

0 comments on commit 675ab25

Please sign in to comment.