Skip to content

Commit 675ab25

Browse files
authored
Fix the exit code when there happens to be an unhandled exception (#1389)
1 parent 7569838 commit 675ab25

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

docs/history/hatch.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4141
- De-select Ruff rule `E501` for the `fmt` command by default since it conflicts with the formatter
4242
- Fix colored output from build targets on the first run (build environment creation status indicator issue)
4343
- Set the `packaging` dependency version as `>=23.2` to avoid its URL validation which can conflict with context formatting
44+
- Fix the exit code when there happens to be an unhandled exception
4445

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

src/hatch/__main__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import sys
2-
31
if __name__ == '__main__':
42
from hatch.cli import main
53

6-
sys.exit(main())
4+
main()

src/hatch/cli/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,13 @@ def hatch(ctx: click.Context, env_name, project, verbose, quiet, color, interact
218218

219219
def main(): # no cov
220220
try:
221-
return hatch(prog_name='hatch', windows_expand_args=False)
221+
hatch(prog_name='hatch', windows_expand_args=False)
222222
except Exception: # noqa: BLE001
223+
import sys
224+
223225
from rich.console import Console
224226

225227
console = Console()
226228
hatch_debug = os.getenv('HATCH_DEBUG') in {'1', 'true'}
227229
console.print_exception(suppress=[click], show_locals=hatch_debug)
228-
return 1
230+
sys.exit(1)

0 commit comments

Comments
 (0)