-
Notifications
You must be signed in to change notification settings - Fork 185
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
[RFC] Throw a special exceptions in Julia callbacks (Fix #770) #772
Conversation
bccf133
to
311d2af
Compare
So...
NULL is not defined. The other one is the one with Unprintable and I'm on it... |
Ok, the second error is... very weird. In short, the solution is removing the parametric type from However, I don't understand why that is the case. So below is a small investigation on the cause. Maybe it's an underlying issue in Julia, or maybe in my implementation? I tracked it down to exactly this line err = PyJlError(e, bt) The error also persists if I try to do t=typeof(e) #executes ok
err = PyJlError{t}(e, bt) In case it might help, this error still happens if you make Unprintable's type printable but not the value. |
I think if you wanted to keep the parametric type you would need an outer constructor But I agree that a parameterized type is not needed here. |
I think you mean |
But let's leave the type as non-parametric. |
(Now tests are passing, except for an unrelated error which I'm not sure why shows up half the time).
Yes, indeed. On of the tests tries throwing an Unprintable object (which is not |
@tkf, hopefully this doesn't cause any problems for pyjulia? |
Thanks for the ping. I ran PyJulia test suite with PyCall |
This PR tries to address the printing of stack traces in Julia callbacks and fix #770, while also leaving the door open for further improvements.
The problem I wanted to solve is the fact that errors and stack traces thrown by a Julia callback executed by python, such as
loses formatting when being displayed.
This is because currently we render the exception to a string when it is thrown, return it to python as a python error, which then is returned to Julia again, and displays it.
This is especially painful in wrapper packages such as Tensorflow.jl, Jax.jl or several others.
In the process formatting is lost.
My solution:
When a Julia callback throws, don't render the callback immediately. Instead return a custom Error type,
PyJlError
, which stores the backtrace.When control is eventually returned to Julia, check if the python error is wrapping a Julia error. If so, show only the Julia one.
This is compatible with JuliaPy, as the rendering of
PyJlError
is handled by the show method.Result:
old:
new: