Skip to content

Commit c886fef

Browse files
committed
Make ExceptionStack a type alias only
Now we match on structure alone, which is argubly a bit ropey but doesn't require a new type. Also allows us to remove show for ExceptionStack, without too many ill effects.
1 parent 3137d44 commit c886fef

File tree

3 files changed

+10
-31
lines changed

3 files changed

+10
-31
lines changed

base/error.jl

+9-14
Original file line numberDiff line numberDiff line change
@@ -91,36 +91,31 @@ function catch_backtrace()
9191
return _reformat_bt(bt[], bt2[])
9292
end
9393

94-
struct ExceptionStack <: AbstractArray{Any,1}
95-
stack
96-
end
97-
9894
"""
9995
current_exceptions(task=current_task(); [inclue_bt=true])
10096
10197
Get the stack of exceptions currently being handled. For nested catch blocks
10298
there may be more than one current exception in which case the most recently
10399
thrown exception is last in the stack. The stack is returned as an
104-
`ExceptionStack` which is an AbstractVector of named tuples
105-
`(exception,backtrace)`. If `backtrace` is false, the backtrace in each pair
106-
will be set to `nothing`.
100+
`ExceptionStack` which is a Vector of named tuples `(exception,backtrace)`. If
101+
`backtrace` is false, the backtrace in each pair will be set to `nothing`.
107102
108103
Explicitly passing `task` will return the current exception stack on an
109104
arbitrary task. This is useful for inspecting tasks which have failed due to
110105
uncaught exceptions.
111106
"""
112107
function current_exceptions(task=current_task(); backtrace=true)
113108
raw = ccall(:jl_get_excstack, Any, (Any,Cint,Cint), task, backtrace, typemax(Cint))
114-
formatted = Any[]
115109
stride = backtrace ? 3 : 1
116-
for i = reverse(1:stride:length(raw))
117-
exc = raw[i]
118-
bt = backtrace ? Base._reformat_bt(raw[i+1],raw[i+2]) : nothing
119-
push!(formatted, (exception=exc,backtrace=bt))
120-
end
121-
ExceptionStack(formatted)
110+
[
111+
(exception=raw[i],
112+
backtrace=backtrace ? Base._reformat_bt(raw[i+1],raw[i+2]) : nothing)
113+
for i = reverse(1:stride:length(raw))
114+
]
122115
end
123116

117+
const ExceptionStack = Array{NamedTuple{(:exception, :backtrace),T}, 1} where {T<:Tuple}
118+
124119
## keyword arg lowering generates calls to this ##
125120
function kwerr(kw, args::Vararg{Any,N}) where {N}
126121
@_noinline_meta

base/errorshow.jl

-17
Original file line numberDiff line numberDiff line change
@@ -628,23 +628,6 @@ function process_backtrace(t::Vector, limit::Int=typemax(Int); skipC = true)
628628
return ret
629629
end
630630

631-
size(s::ExceptionStack) = size(s.stack)
632-
getindex(s::ExceptionStack, i) = s.stack[i]
633-
634-
function show(io::IO, ::MIME"text/plain", stack::ExceptionStack)
635-
nexc = length(stack)
636-
printstyled(io, nexc, "-element ExceptionStack", nexc == 0 ? "" : ":\n")
637-
for i = nexc:-1:1
638-
if nexc != 1
639-
printstyled(io, "caused by [exception ", i, "]\n", color=:light_black)
640-
end
641-
exc,bt = stack[i]
642-
showerror(io, exc, bt, backtrace=bt!==nothing)
643-
println(io)
644-
end
645-
end
646-
show(io::IO, stack::ExceptionStack) = show(io, MIME"text/plain"(), stack)
647-
648631
@noinline function throw_eachindex_mismatch(::IndexLinear, A...)
649632
throw(DimensionMismatch("all inputs to eachindex must have the same indices, got $(join(LinearIndices.(A), ", ", " and "))"))
650633
end

stdlib/Logging/src/ConsoleLogger.jl

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function showvalue(io, e::Tuple{Exception,Any})
4848
ex,bt = e
4949
showerror(io, ex, bt; backtrace = bt!=nothing)
5050
end
51+
showvalue(io, stack::Base.ExceptionStack) = Base.display_error(io, stack)
5152
showvalue(io, ex::Exception) = showerror(io, ex)
5253

5354
function default_logcolor(level)

0 commit comments

Comments
 (0)