-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Remove exception catching for __init__ functions, add InitError exception type #12576
Conversation
+1. I don't think that code in |
Marking this as 0.4.0 as this is a breaking change, that should get merged before feature freeze. |
Indeed, I think this needs to get resolved. |
👍 |
If it should behave like the same code at the end of a module, we need to catch the exception and wrap it in a |
@ivarne That sounds good. The principle here is that errors should not be swept under the rug (printing something to the terminal just doesn't cut it when you have lots of non-interactive processes anyway, and can be dangerous if the output device is been redirected to something else) |
I'm still confused by why we would ever be ignoring errors in |
Jeff did the implementation of this. I think the basic assumption was that a failure in a
and Foo did stuff like have multiple submodules with As some food for thought, it may not be correct to propagate errors for code loaded from conditional modules (#6884) since that code is not run until after the matching module. |
@ivarne, I agree with wrapping it in a
or maybe defining a new |
It would definitely be nice to have I should have some time this evening to update the branch. |
f03ab59
to
ddd476b
Compare
Updated to add a new |
Looks good. Maybe add @test_throws InitError include_string("module TestInitError\n__init__() = error(\"foo\")\nend") to |
Probably you should change precompilableerror(ex::Union{LoadError,InitError}, c) = precompilableerror(ex.error, c) to cover the (unlikely) event that the user calls |
function showerror(io::IO, ex::InitError, bt; backtrace=true) | ||
print(io, "InitError: ") | ||
showerror(io, ex.error, bt, backtrace=backtrace) | ||
print(io, "\nduring initialization of module $(ex.mod)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this should be:
showerror(io::IO, ex::InitError) = print(io, "InitError: during initialization of module $(ex.mod"))
the backtrace will already be appended
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakebolewski, It seems like @phobon's code is correct; it should be analogous to showerror(io::IO, ex::LoadError)
, and you need to show ex.error
at minimum, and you need to pass the backtrace through in case ex.error
has a special backtrace handler.
the precompilation has already finished and saved the file by then, thus it seems like a bad place to be trying to assert |
@vtjnash, I agree that we normally shouldn't encourage people to call |
@stevengj, currently if you define a module at the REPL, exceptions do not get wrapped in a |
@phobon, as I understand it, On the other hand, |
i think you need a try/catch/rethrow at https://github.com/phobon/julia/blob/ddd476b1b7e5c3af0d34432109d37693604b11c6/src/toplevel.c#L208-L215 to clear the reinit list after an error to avoid leaving it in an invalid state |
@vtjnash, I'm not completely sure I know what "clear the reinit list" entails. Do these lines do the job?
Is the same concern relevant for restoring compiled modules as well? |
clear it by resetting the top pointer: precompiled modules have their own array, so i don't think they should be a problem |
@@ -145,7 +145,7 @@ function show(io::IO, ex::PrecompilableError) | |||
end | |||
end | |||
precompilableerror(ex::PrecompilableError, c) = ex.isprecompilable == c | |||
precompilableerror(ex::LoadError, c) = precompilableerror(ex.error, c) | |||
precompilableerror(ex::Union{LoadError,InitError}, c) = precompilableerror(ex.error, c) | |||
precompilableerror(ex, c) = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is useful for other cases, but this change kind of begs for abstract WrappedException <: Exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had thought about it, but it did seem like a pretty small corner case. I suppose there's no harm in future-proofing though.
Add docs for InitError
Implemented by LoadError and InitError
1d9ce0a
to
5898d2e
Compare
Remove exception catching for __init__ functions, add InitError exception type
I did have some interest in running this branch on the package evaluator but started to hesitate digging into when I saw it would require some hacking. Is there some fork or branch where someone has already set up this capability? And just saw the merge went through... |
Glad to see this resolved, thanks for the feedback everyone! |
Thanks @phobon, great work. |
Not much? It's a few clicks on the buildbots by anyone who has a login to make a custom generic binary from any branch or PR, then should be only one or two lines to change in PackageEvaluator to point it to a different download. |
It will be great when this can be done just by pinging a bot from Github. |
Webhooks aren't hard to write. Just a matter of hardware to run it on and plumbing it together. |
Hopefully soon (end of the month) we will have the hardware. |
It would be nice to enable PackageEvaluator to check out and build an arbitrary branch so anyone without buildbot access could run it locally, or maybe on their own cloud computing account. |
Recent incarnations of PackageEvaluator don't build from source any more, but the buildbots are good at that. You can run |
That's fine, but will they be freely usable by anyone who wants? If not, then in the interest of simplicity it would seem useful to provide an option to PackageEvaluator that would have it also build julia from source. |
@phobon I'd accept a pull request for that. I'd be a very short PR, its a really simple system. |
Custom builds from the buildbots get uploaded to https://s3.amazonaws.com/julianightlies/ with a sha, just like normal nightlies. They'll stay up there for roughly 3-4 weeks. In fact the releases of 0.3 have been made that way, just manually moving the files over from julianightlies to julialang once a month. |
Note that this change is really bad for embedding. Now when any dependency libraries aren't present, Julia can't start at all instead of being just unable to use the functionality from that library. |
In that case the library should |
Or it should be possible to put the |
If we actually manage to agree on something to move out of Base in #5155, we wouldn't need to |
PCRE, GMP, dSFMT, openblas, and suitesparse_wrapper all need to be turned into warnings instead of |
Or pull them out of base? dSFMT adds significantly to Julia's startup time (also openblas, but less so) |
Yes, but not right now. We need to make the lack of their presence non-fatal right now, otherwise 0.4.0 will be substantially less usable for embedders. |
Hopefully pulling them out of base will be done early in 0.5, but this change is already in 0.4, so it needs to be dealt with somehow now. |
else { | ||
jl_rethrow_other(jl_new_struct(jl_initerror_type, m->name, | ||
jl_exception_in_transit)); | ||
jl_printf(JL_STDERR, "\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's really weird to print something if the exception isn't being handled. If you tried to trap and hide all of these exceptions, you would still get empty lines scrolling in stderr.
EDIT: I see this is after a rethrow so I guess it's just dead code.
@tkelman Very good point. All I can think of at the moment is to wrap those specific Base It's also quite likely I was thinking of this issue when I put the try-catch in there originally. Before |
To be continued in #12742 ... |
This PR is to continue the discussion from #12505 with a concrete implementation candidate. Sometime later this week I am interested to try running the package evaluator to see what level of breakage it causes due to people not bothering to fix warnings.
@JeffBezanson @StefanKarpinski @vtjnash