Skip to content

Commit a526662

Browse files
c42fJeffBezanson
authored andcommitted
Revert "Don't use jl_rethrow_other for LoadError/InitError" (#31963)
This reverts commit d3dbe86. + fixup new tests in backtrace.jl
1 parent 4c28b36 commit a526662

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

base/errorshow.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,18 @@ function showerror(io::IO, ex, bt; backtrace=true)
8585
end
8686

8787
function showerror(io::IO, ex::LoadError, bt; backtrace=true)
88-
print(io, "Error while loading expression starting at ", ex.file, ":", ex.line)
88+
print(io, "LoadError: ")
89+
showerror(io, ex.error, bt, backtrace=backtrace)
90+
print(io, "\nin expression starting at $(ex.file):$(ex.line)")
8991
end
9092
showerror(io::IO, ex::LoadError) = showerror(io, ex, [])
9193

92-
showerror(io::IO, ex::InitError) = print(io, "InitError during initialization of module ", ex.mod)
94+
function showerror(io::IO, ex::InitError, bt; backtrace=true)
95+
print(io, "InitError: ")
96+
showerror(io, ex.error, bt, backtrace=backtrace)
97+
print(io, "\nduring initialization of module ", ex.mod)
98+
end
99+
showerror(io::IO, ex::InitError) = showerror(io, ex, [])
93100

94101
function showerror(io::IO, ex::DomainError)
95102
if isa(ex.val, AbstractArray)

src/ast.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,8 @@ jl_value_t *jl_parse_eval_all(const char *fname,
892892
if (jl_loaderror_type == NULL)
893893
jl_rethrow();
894894
else
895-
jl_throw(jl_new_struct(jl_loaderror_type, form, result,
896-
jl_current_exception()));
895+
jl_rethrow_other(jl_new_struct(jl_loaderror_type, form, result,
896+
jl_current_exception()));
897897
}
898898
JL_GC_POP();
899899
return result;
@@ -1050,8 +1050,8 @@ static jl_value_t *jl_invoke_julia_macro(jl_array_t *args, jl_module_t *inmodule
10501050
else
10511051
margs[0] = jl_cstr_to_string("<macrocall>");
10521052
margs[1] = jl_fieldref(lno, 0); // extract and allocate line number
1053-
jl_throw(jl_new_struct(jl_loaderror_type, margs[0], margs[1],
1054-
jl_current_exception()));
1053+
jl_rethrow_other(jl_new_struct(jl_loaderror_type, margs[0], margs[1],
1054+
jl_current_exception()));
10551055
}
10561056
}
10571057
ptls->world_age = last_age;

src/toplevel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ void jl_module_run_initializer(jl_module_t *m)
7979
jl_rethrow();
8080
}
8181
else {
82-
jl_throw(jl_new_struct(jl_initerror_type, m->name,
83-
jl_current_exception()));
82+
jl_rethrow_other(jl_new_struct(jl_initerror_type, m->name,
83+
jl_current_exception()));
8484
}
8585
}
8686
}

test/backtrace.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ let trace = try
199199
200200
""", "a_filename")
201201
catch
202-
stacktrace(Base.catch_stack()[end-1][2]) # Ignore LoadError
202+
stacktrace(catch_backtrace())
203203
end
204204
@test trace[1].func == Symbol("top-level scope")
205205
@test trace[1].file == :a_filename
@@ -213,7 +213,7 @@ let trace = try
213213
214214
""", "a_filename")
215215
catch
216-
stacktrace(Base.catch_stack()[end-1][2]) # Ignore LoadError
216+
stacktrace(catch_backtrace())
217217
end
218218
@test trace[1].func == Symbol("top-level scope")
219219
@test trace[1].file == :a_filename

test/errorshow.jl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,15 @@ end
156156
macro except_strbt(expr, err_type)
157157
errmsg = "expected failure, but no exception thrown for $expr"
158158
return quote
159-
let err = nothing, bt = nothing
159+
let err = nothing
160160
try
161161
$(esc(expr))
162162
catch err
163-
bt = catch_backtrace()
164163
end
165164
err === nothing && error($errmsg)
166165
@test typeof(err) === $(esc(err_type))
167166
buf = IOBuffer()
168-
showerror(buf, err, bt)
167+
showerror(buf, err, catch_backtrace())
169168
String(take!(buf))
170169
end
171170
end
@@ -555,12 +554,3 @@ let buf = IOBuffer()
555554
Base.show_method_candidates(buf, Base.MethodError(sin, Tuple{NoMethodsDefinedHere}))
556555
@test length(take!(buf)) !== 0
557556
end
558-
559-
@testset "Nested errors" begin
560-
# LoadError and InitError used to print the nested exception.
561-
# This is now dealt with via the exception stack so these print very simply:
562-
@test sprint(Base.showerror, LoadError("somefile.jl", 10, ErrorException("retained for backward compat"))) ==
563-
"Error while loading expression starting at somefile.jl:10"
564-
@test sprint(Base.showerror, InitError(:some_module, ErrorException("retained for backward compat"))) ==
565-
"InitError during initialization of module some_module"
566-
end

test/precompile.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ try
372372
error("break me")
373373
end
374374
""")
375-
@test_warn r"ERROR: Error while loading expression starting at.*FooBar2.*caused by.*break me"s try
375+
@test_warn "ERROR: LoadError: break me\nStacktrace:\n [1] error" try
376376
Base.require(Main, :FooBar2)
377377
error("\"LoadError: break me\" test failed")
378378
catch exc

0 commit comments

Comments
 (0)