-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update exception handling in tools #2594
Conversation
src/ctapipe/core/tool.py
Outdated
@@ -443,6 +449,19 @@ def run(self, argv=None, raises=False): | |||
Provenance().finish_activity( | |||
activity_name=self.name, status="interrupted", exit_code=exit_status | |||
) | |||
except self.custom_exceptions as err: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should still catch the SystemExit
with error code != 0 case here, I think this was the cause of the issue for #1881
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, SystemExit treatment is added back
This comment has been minimized.
This comment has been minimized.
btw.: I simplified the |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
How about introducing a member variable
However, I don't really see why this is different to just doing this in the tool:
|
The exceptions can be raised in the components that tool uses, in this case what you propose is still possible, but requires additional boiler plate try-except code in every tool. Here, for the price of a bit more complex exception handling, we can properly catch all the exceptions raised in the Tool itself or in the components it uses, and also keep the definition of exit codes tightly coupled to exceptions themselves. Adding an |
That means a component down the line would already specify the exit code? What if a component is used in more than one tool? |
I think it would be much more straight forward to catch the exception where it appears in your tool:
|
I'm in favor of defining custom exceptions specifying the exit code, i.e. one exception can be reused between the components or tools if needed and the exit code is tied to this particular exception.
I don't see a problem here... can you elaborate?
This is an option, but as I wrote above, would require more boiler plate code above. Since I'm still in favor of having exit code being tied to the custom exception, this should become like this:
which is basically the same that's added to the |
CI failed because of broken provenance, will rebase as soon as #2595 is merged |
47b4139
to
45a0fd4
Compare
- Remove SystemExit handling in `Tool.run()` - Add a possibility to register custom exceptions and handle them in `Tool.run()` with the preservation of the exit code.
- Simplify SystemExit handling - Remove custom exception registration, but add a treatment of the custom exit codes when catching generic Exception
45a0fd4
to
9da3faf
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some documentation on this to the docstring of Tool
.
Analysis Details0 IssuesCoverage and DuplicationsProject ID: cta-observatory_ctapipe_AY52EYhuvuGcMFidNyUs |
Following some real-world experience with my own changes proposed before, I believe this would be a better way to handle custom runtime exceptions with the custom exit codes.
Remove SystemExit handling inTool.run()
Tool.run()
with the preservation of the exit code.