Skip to content

Commit ce600a0

Browse files
authored
Enforce ExceptionStack stack type (#59133)
The code that processes these requires these to be this NamedTuple, so enforce that so that it fails on construction rather than on access. Also fix the one place that was passing a regular tuple. Fixes #59132.
1 parent 90e3c1a commit ce600a0

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

base/client.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function repl_cmd(cmd, out)
7171
catch
7272
# Julia throws an exception if it can't find the cmd (which may be the shell itself), but the stack trace isn't useful
7373
lasterr = current_exceptions()
74-
lasterr = ExceptionStack([(exception = e[1], backtrace = [] ) for e in lasterr])
74+
lasterr = ExceptionStack(NamedTuple[(exception = e[1], backtrace = [] ) for e in lasterr])
7575
invokelatest(display_error, lasterr)
7676
end
7777
end
@@ -99,7 +99,7 @@ function scrub_repl_backtrace(bt)
9999
return bt
100100
end
101101
scrub_repl_backtrace(stack::ExceptionStack) =
102-
ExceptionStack(Any[(;x.exception, backtrace = scrub_repl_backtrace(x.backtrace)) for x in stack])
102+
ExceptionStack(NamedTuple[(;x.exception, backtrace = scrub_repl_backtrace(x.backtrace)) for x in stack])
103103

104104
istrivialerror(stack::ExceptionStack) =
105105
length(stack) == 1 && length(stack[1].backtrace) 1 && !isa(stack[1].exception, MethodError)

base/error.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ function catch_backtrace()
135135
return _reformat_bt(bt::Vector{Ptr{Cvoid}}, bt2::Vector{Any})
136136
end
137137

138-
struct ExceptionStack <: AbstractArray{Any,1}
139-
stack::Array{Any,1}
138+
struct ExceptionStack <: AbstractArray{NamedTuple{(:exception, :backtrace)},1}
139+
stack::Array{NamedTuple{(:exception, :backtrace)},1}
140140
end
141141

142142
"""
@@ -159,7 +159,7 @@ uncaught exceptions.
159159
"""
160160
function current_exceptions(task::Task=current_task(); backtrace::Bool=true)
161161
raw = ccall(:jl_get_excstack, Any, (Any,Cint,Cint), task, backtrace, typemax(Cint))::Vector{Any}
162-
formatted = Any[]
162+
formatted = NamedTuple{(:exception, :backtrace)}[]
163163
stride = backtrace ? 3 : 1
164164
for i = reverse(1:stride:length(raw))
165165
exc = raw[i]

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ cd(@__DIR__) do
415415
# deserialization errors or something similar. Record this testset as Errored.
416416
fake = Test.DefaultTestSet(testname)
417417
fake.time_end = fake.time_start + duration
418-
Test.record(fake, Test.Error(:nontest_error, testname, nothing, Base.ExceptionStack(Any[(resp, [])]), LineNumberNode(1), nothing))
418+
Test.record(fake, Test.Error(:nontest_error, testname, nothing, Base.ExceptionStack(NamedTuple[(;exception = resp, backtrace = [])]), LineNumberNode(1), nothing))
419419
Test.push_testset(fake)
420420
Test.record(o_ts, fake)
421421
Test.pop_testset()
@@ -424,7 +424,7 @@ cd(@__DIR__) do
424424
for test in all_tests
425425
(test in completed_tests) && continue
426426
fake = Test.DefaultTestSet(test)
427-
Test.record(fake, Test.Error(:test_interrupted, test, nothing, Base.ExceptionStack(Any[("skipped", [])]), LineNumberNode(1), nothing))
427+
Test.record(fake, Test.Error(:test_interrupted, test, nothing, Base.ExceptionStack(NamedTuple[(;exception = "skipped", backtrace = [])]), LineNumberNode(1), nothing))
428428
Test.push_testset(fake)
429429
Test.record(o_ts, fake)
430430
Test.pop_testset()

0 commit comments

Comments
 (0)