-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
END_HANDLE_TH_ERRORS_PYBIND prevents pybind11 Exception translation #34172
Comments
cc @peterbell10 that changed the CATCH_TH_ERROR to CATCH_ALL_ERROR in there #30588. Is that the expected behavior or a typo that we should fix? |
Prior to #30588, AFAIK, there is no way to catch a generic |
Ho right so the reason is to translate cpp names into python names. I guess we need a to make a choice:
|
…as-is" Mitigates the effect of #34172 for saved tensor hooks BC Breaking message: - Exceptions raised inside the pack and unpack hooks are no longer erroneously converted to RuntimeErrors. You should update your code to handle the original type of exception raised. cc ezyang gchanan [ghstack-poisoned]
…as-is" Mitigates the effect of #34172 for saved tensor hooks BC Breaking message: - Exceptions raised inside the pack and unpack hooks are no longer erroneously converted to RuntimeErrors. You should update your code to handle the original type of exception raised. cc ezyang gchanan [ghstack-poisoned]
Mitigates the effect of #34172 for saved tensor hooks BC Breaking message: - Exceptions raised inside the pack and unpack hooks are no longer erroneously converted to RuntimeErrors. You should update your code to handle the original type of exception raised. Pull Request resolved: #94456 Approved by: https://github.com/albanD
🐛 Bug
pybind11 allows exception translation by catching and translating C++ exceptions. This is similar to what we do within END_HANDLE_TH_ERRORS_PYBIND as well, in the sense that we also inspect the thrown type and handle it differently in some cases (e.g. py::builtin_exception). However, due to CATCH_ALL_ERRORS we prevent pybind from catching something like a std::out_of_range and instead bubble up a PyExc_RuntimeError. For the pybind11 user that's writing code out of tree and uses wrap_pybind_function as exception translation for at:: specific errors this means they have to setup their own translation within the wrapped function to get the proper error.
To Reproduce
To reproduce this behavior register a simple pybind11 function that throws out_of_range and see it turn into RuntimeError and not IndexError. I can provide a code snippet if needed.
Expected behavior
I'd expect us to simply forward the exception and rely on pybind11 to do the proper translation for the listed functions, so we can simply forward them. I think this is ok, because END_HANDLE_TH_ERROR_PYBIND is explicitly written for pybind11.
Environment
Compiled from source
Additional context
This showed up in the context of porting NestedTensor.to_tensor into C++.
The text was updated successfully, but these errors were encountered: