Skip to content

Commit

Permalink
Merge pull request #2575 from cta-observatory/fix-sysexit-0
Browse files Browse the repository at this point in the history
Bugfix: don't intercept normal SystemExit(0) in Tool
  • Loading branch information
kosack authored Jul 8, 2024
2 parents b63a7d4 + 465f17e commit 0a0f5f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/changes/2575.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a redundant error message in ``Tool`` caused by normal ``SystemExit(0)``
26 changes: 14 additions & 12 deletions src/ctapipe/core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,18 +452,20 @@ def run(self, argv=None, raises=False):
if raises:
raise
except SystemExit as err:
if raises:
raise # do not re-intercept in tests
else:
exit_status = err.code
self.log.exception(
"Caught SystemExit with exit code %s", exit_status
)
Provenance().finish_activity(
activity_name=self.name,
status="error",
exit_code=exit_status,
)
exit_status = err.code
# Do nothing if SystemExit was called with the exit code 0 (e.g. with -h option)
if exit_status != 0:
if raises:
raise # do not re-intercept in tests
else:
self.log.exception(
"Caught SystemExit with exit code %s", exit_status
)
Provenance().finish_activity(
activity_name=self.name,
status="error",
exit_code=exit_status,
)
finally:
if not {"-h", "--help", "--help-all"}.intersection(self.argv):
self.write_provenance()
Expand Down

0 comments on commit 0a0f5f1

Please sign in to comment.