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

Capture exceptions raised from PyFunctionLibrary functions for debuggability. #65043

Merged
merged 1 commit into from Apr 9, 2024

Conversation

copybara-service[bot]
Copy link

Capture exceptions raised from PyFunctionLibrary functions for debuggability.

Before this change, when there is an error raised inside a PyFunctionLibrary method, the program would crash with a long stack trace, something like the following:

<super-long c++ stack trace with no meaningful information>

libc++abi: terminating due to uncaught exception of type pybind11::error_already_set: ValueError: Failed to run graph for post-training quantization calibration.

The information in the raised exception is lost in this case, hindering debuggability.

This change instead returns regular value None back to the c++ layer to indicate error, and prints the exception chain from the python side.
It prints out the exact error message one would see when an exception is raised from regular python script.

The return values of PyFunctionLibrary methods are all changed to std::optional<T>, where T is the successful return value and std::nullopt indicates error.
To avoid conflict btw erroneous None, methods that do not essentially return a value now returns a dummy True to indicate successful run.

@copybara-service copybara-service bot force-pushed the exported_pr_621772760 branch 2 times, most recently from 3b46dea to 9322a96 Compare April 9, 2024 05:17
…ggability.

Before this change, when there is an error raised inside a `PyFunctionLibrary` method, the program would crash with a long stack trace, something like the following:

```
<super-long c++ stack trace with no meaningful information>

libc++abi: terminating due to uncaught exception of type pybind11::error_already_set: ValueError: Failed to run graph for post-training quantization calibration.
```

The information in the raised exception is lost in this case, hindering debuggability.

This change instead returns regular value `None` back to the c++ layer to indicate error, and prints the exception chain from the python side.
It prints out the exact error message one would see when an exception is raised from regular python script.

The return values of `PyFunctionLibrary` methods are all changed to `std::optional<T>`, where `T` is the successful return value and `std::nullopt` indicates error.
To avoid conflict btw erroneous `None`, methods that do not essentially return a value now returns a dummy `True` to indicate successful run.

PiperOrigin-RevId: 623055737
@copybara-service copybara-service bot merged commit 34a9f25 into master Apr 9, 2024
@copybara-service copybara-service bot deleted the exported_pr_621772760 branch April 9, 2024 06:33
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.

None yet

1 participant