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

Revert "Don't use jl_rethrow_other for LoadError/InitError" (fix #31830) #31963

Merged
merged 1 commit into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,18 @@ function showerror(io::IO, ex, bt; backtrace=true)
end

function showerror(io::IO, ex::LoadError, bt; backtrace=true)
print(io, "Error while loading expression starting at ", ex.file, ":", ex.line)
print(io, "LoadError: ")
showerror(io, ex.error, bt, backtrace=backtrace)
print(io, "\nin expression starting at $(ex.file):$(ex.line)")
end
showerror(io::IO, ex::LoadError) = showerror(io, ex, [])

showerror(io::IO, ex::InitError) = print(io, "InitError during initialization of module ", ex.mod)
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)
end
showerror(io::IO, ex::InitError) = showerror(io, ex, [])

function showerror(io::IO, ex::DomainError)
if isa(ex.val, AbstractArray)
Expand Down
8 changes: 4 additions & 4 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,8 @@ jl_value_t *jl_parse_eval_all(const char *fname,
if (jl_loaderror_type == NULL)
jl_rethrow();
else
jl_throw(jl_new_struct(jl_loaderror_type, form, result,
jl_current_exception()));
jl_rethrow_other(jl_new_struct(jl_loaderror_type, form, result,
jl_current_exception()));
}
JL_GC_POP();
return result;
Expand Down Expand Up @@ -1050,8 +1050,8 @@ static jl_value_t *jl_invoke_julia_macro(jl_array_t *args, jl_module_t *inmodule
else
margs[0] = jl_cstr_to_string("<macrocall>");
margs[1] = jl_fieldref(lno, 0); // extract and allocate line number
jl_throw(jl_new_struct(jl_loaderror_type, margs[0], margs[1],
jl_current_exception()));
jl_rethrow_other(jl_new_struct(jl_loaderror_type, margs[0], margs[1],
jl_current_exception()));
}
}
ptls->world_age = last_age;
Expand Down
4 changes: 2 additions & 2 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ void jl_module_run_initializer(jl_module_t *m)
jl_rethrow();
}
else {
jl_throw(jl_new_struct(jl_initerror_type, m->name,
jl_current_exception()));
jl_rethrow_other(jl_new_struct(jl_initerror_type, m->name,
jl_current_exception()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ let trace = try

""", "a_filename")
catch
stacktrace(Base.catch_stack()[end-1][2]) # Ignore LoadError
stacktrace(catch_backtrace())
end
@test trace[1].func == Symbol("top-level scope")
@test trace[1].file == :a_filename
Expand All @@ -213,7 +213,7 @@ let trace = try

""", "a_filename")
catch
stacktrace(Base.catch_stack()[end-1][2]) # Ignore LoadError
stacktrace(catch_backtrace())
end
@test trace[1].func == Symbol("top-level scope")
@test trace[1].file == :a_filename
Expand Down
14 changes: 2 additions & 12 deletions test/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,15 @@ end
macro except_strbt(expr, err_type)
errmsg = "expected failure, but no exception thrown for $expr"
return quote
let err = nothing, bt = nothing
let err = nothing
try
$(esc(expr))
catch err
bt = catch_backtrace()
end
err === nothing && error($errmsg)
@test typeof(err) === $(esc(err_type))
buf = IOBuffer()
showerror(buf, err, bt)
showerror(buf, err, catch_backtrace())
String(take!(buf))
end
end
Expand Down Expand Up @@ -555,12 +554,3 @@ let buf = IOBuffer()
Base.show_method_candidates(buf, Base.MethodError(sin, Tuple{NoMethodsDefinedHere}))
@test length(take!(buf)) !== 0
end

@testset "Nested errors" begin
# LoadError and InitError used to print the nested exception.
# This is now dealt with via the exception stack so these print very simply:
@test sprint(Base.showerror, LoadError("somefile.jl", 10, ErrorException("retained for backward compat"))) ==
"Error while loading expression starting at somefile.jl:10"
@test sprint(Base.showerror, InitError(:some_module, ErrorException("retained for backward compat"))) ==
"InitError during initialization of module some_module"
end
2 changes: 1 addition & 1 deletion test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ try
error("break me")
end
""")
@test_warn r"ERROR: Error while loading expression starting at.*FooBar2.*caused by.*break me"s try
@test_warn "ERROR: LoadError: break me\nStacktrace:\n [1] error" try
Base.require(Main, :FooBar2)
error("\"LoadError: break me\" test failed")
catch exc
Expand Down