Skip to content

Avoid catch (...) for expected import numpy failures #3974

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

Merged

Conversation

rwgk
Copy link
Collaborator

@rwgk rwgk commented May 26, 2022

Description

Extracted from PR #3964, where the catch (...) happened to cause significant confusion because they are silently dropping any kind of error. This is likely to cause more confusion in future development work. Narrowing down to catch (const py::error_already_set &) is a simple way to significantly reduce the potential for silently dropping important errors (although that is still not perfect).

Suggested changelog entry:

* Avoid catching unrelated errors when importing numpy.

@rwgk rwgk marked this pull request as ready for review May 26, 2022 11:14
@rwgk rwgk requested a review from Skylion007 May 26, 2022 11:14
@henryiii
Copy link
Collaborator

Can we restrict any usage of catch (...) in the codebase?

Copy link
Collaborator

@Skylion007 Skylion007 left a comment

Choose a reason for hiding this comment

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

LGTM, let's merge it.

@Skylion007
Copy link
Collaborator

Can we restrict any usage of catch (...) in the codebase?

@henryiii Unfortunately, no. We need to use it for exception translators / exception handling so at least need to be present there. We also need it for noexcept handling as well. Finally, I am not aware of clang-tidy rules or such to restrict this anyway.

@henryiii henryiii merged commit 8d14e66 into pybind:master May 26, 2022
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label May 26, 2022
@rwgk rwgk deleted the avoid_catch_any_for_expected_import_errors branch May 31, 2022 20:45
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants