-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,13 @@ function showerror(io::IO, ex::LoadError, bt; backtrace=true) | |
end | ||
showerror(io::IO, ex::LoadError) = showerror(io, ex, []) | ||
|
||
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 commentThe 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 commentThe 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 |
||
end | ||
showerror(io::IO, ex::InitError) = showerror(io, ex, []) | ||
|
||
function showerror(io::IO, ex::DomainError, bt; backtrace=true) | ||
print(io, "DomainError:") | ||
for b in bt | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -542,9 +542,14 @@ void jl_module_run_initializer(jl_module_t *m) | |
jl_apply(f, NULL, 0); | ||
} | ||
JL_CATCH { | ||
jl_printf(JL_STDERR, "WARNING: error initializing module %s:\n", m->name->name); | ||
jl_static_show(JL_STDERR, jl_exception_in_transit); | ||
jl_printf(JL_STDERR, "\n"); | ||
if (jl_initerror_type == NULL) { | ||
jl_rethrow(); | ||
} | ||
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 commentThe 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. |
||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,7 @@ jl_value_t *jl_eval_module_expr(jl_expr_t *ex) | |
jl_typeerror_type = NULL; | ||
jl_methoderror_type = NULL; | ||
jl_loaderror_type = NULL; | ||
jl_initerror_type = NULL; | ||
jl_current_task->tls = jl_nothing; // may contain an entry for :SOURCE_FILE that is not valid in the new base | ||
} | ||
// export all modules from Main | ||
|
@@ -205,12 +206,18 @@ jl_value_t *jl_eval_module_expr(jl_expr_t *ex) | |
arraylist_push(&module_stack, newm); | ||
|
||
if (outermost == NULL || jl_current_module == jl_main_module) { | ||
size_t i, l=module_stack.len; | ||
for(i = stackidx; i < l; i++) { | ||
jl_module_load_time_initialize((jl_module_t*)module_stack.items[i]); | ||
JL_TRY { | ||
size_t i, l=module_stack.len; | ||
for(i = stackidx; i < l; i++) { | ||
jl_module_load_time_initialize((jl_module_t*)module_stack.items[i]); | ||
} | ||
assert(module_stack.len == l); | ||
module_stack.len = stackidx; | ||
} | ||
JL_CATCH { | ||
module_stack.len = stackidx; | ||
jl_rethrow(); | ||
} | ||
assert(module_stack.len == l); | ||
module_stack.len = stackidx; | ||
} | ||
|
||
return (jl_value_t*)newm; | ||
|
@@ -585,8 +592,13 @@ jl_value_t *jl_parse_eval_all(const char *fname, size_t len) | |
jl_rethrow(); | ||
} | ||
else { | ||
jl_rethrow_other(jl_new_struct(jl_loaderror_type, fn, ln, | ||
jl_exception_in_transit)); | ||
if(jl_typeis(jl_exception_in_transit, jl_initerror_type)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this makes sense. Whether an error causes loading a file to fail is orthogonal to the underlying cause of the error. For example if this is "x.jl":
we won't get a LoadError for loading x.jl. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, I think I implicitly assumed this would only get used in one-file-one-module scenarios. It seems the most appropriate thing would be to run the initializers only after all the code has been loaded, but I suppose that is quite a major change. Is a doubly wrapped exception what makes the most sense then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just ditch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just double-wrapping the exception is probably better. That way the decision to have InitError is orthogonal to how everything else works. I'm not sure what you can do by catching InitErrors, but at least they provide more information for printing exceptions, which seems harmless enough for now. |
||
jl_rethrow(); | ||
} | ||
else { | ||
jl_rethrow_other(jl_new_struct(jl_loaderror_type, fn, ln, | ||
jl_exception_in_transit)); | ||
} | ||
} | ||
} | ||
jl_stop_parsing(); | ||
|
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.