Skip to content
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

Ensure main() catches all exceptions #123

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

Pennycook
Copy link
Contributor

Previously the exception handling was outside of main(), which meant that exceptions were only caught when codebasin was launched as a module (i.e., with python3 -m codebasin); the codebasin script generated by pyproject.toml did not catch exceptions.

Related issues

N/A

Proposed changes

  • Add another level of indirection: main() calls _main() and catches all exceptions.

Previously the exception handling was outside of main(), which meant
that exceptions were only caught when codebasin was launched as a module
(i.e., with python3 -m codebasin); the codebasin script generated by
pyproject.toml did not catch exceptions.

Signed-off-by: John Pennycook <[email protected]>
@Pennycook Pennycook added the bug Something isn't working label Oct 11, 2024
@Pennycook Pennycook added this to the 2.0.0 milestone Oct 11, 2024
@Pennycook Pennycook requested a review from laserkelvin October 11, 2024 09:31
Copy link
Contributor

@laserkelvin laserkelvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a second to understand the case, but I think I get it now.

I feel like _main and main naming can be confusing, despite being guilty of doing it myself in PyTorch somewhat frequently. Could we not just indent the entirety of main inside a try/except block instead?

@Pennycook
Copy link
Contributor Author

I feel like _main and main naming can be confusing, despite being guilty of doing it myself in PyTorch somewhat frequently. Could we not just indent the entirety of main inside a try/except block instead?

We could indent the entirety of main, but then we'd have something like 8 levels of indentation in that function. The best solution would be to break things up into functions that can then be called by main(), which would also allow us to write unit tests for those functions. I'm thinking of this as a short-term fix to make sure we don't leak exceptions.

@Pennycook Pennycook merged commit 3732c72 into intel:main Nov 5, 2024
3 checks passed
@Pennycook Pennycook deleted the main-exceptions branch November 5, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants