Skip to content

Commit

Permalink
Correct Tool behavior in case of SystemExit
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Jul 16, 2024
1 parent a8df05e commit 9e637a3
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/ctapipe/core/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,21 +453,19 @@ def run(self, argv=None, raises=False):
raise
except SystemExit as err:
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 RuntimeError(
f"Tool unexpectedly exited with status code {exit_status}"
) from err
else:
self.log.critical(
"Caught SystemExit with exit code %s", exit_status
)
Provenance().finish_activity(
activity_name=self.name,
status="error",
exit_code=exit_status,
)
if exit_status == 0:
# finish normally
Provenance().finish_activity(activity_name=self.name)
else:
# finish with error
self.log.critical(
"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 9e637a3

Please sign in to comment.