84
84
85
85
function scrub_repl_backtrace (bt)
86
86
if bt != = nothing && ! (bt isa Vector{Any}) # ignore our sentinel value types
87
- bt = stacktrace (bt)
87
+ bt = bt isa Vector{StackFrame} ? copy (bt) : stacktrace (bt)
88
88
# remove REPL-related frames from interactive printing
89
89
eval_ind = findlast (frame -> ! frame. from_c && frame. func === :eval , bt)
90
90
eval_ind === nothing || deleteat! (bt, eval_ind: length (bt))
91
91
end
92
92
return bt
93
93
end
94
+ scrub_repl_backtrace (stack:: ExceptionStack ) =
95
+ ExceptionStack ([(exception = x[1 ], backtrace = scrub_repl_backtrace (x[2 ])) for x in stack])
96
+
97
+ istrivialerror (stack:: ExceptionStack ) =
98
+ length (stack) == 1 && length (stack[1 ]. backtrace) ≤ 1
99
+ # frame 1 = top level; assumes already went through scrub_repl_backtrace
94
100
95
- function display_error (io:: IO , er, bt)
96
- printstyled (io, " ERROR: " ; bold= true , color= Base. error_color ())
97
- bt = scrub_repl_backtrace (bt)
98
- stack = ExceptionStack ([(exception = er, backtrace = bt)])
99
- istrivial = length (bt) ≤ 1 # frame 1 = top level
100
- ! istrivial && ccall (:jl_set_global , Cvoid, (Any, Any, Any), Main, :err , stack)
101
- showerror (IOContext (io, :limit => true ), er, bt, backtrace = bt!= = nothing )
102
- println (io)
103
- end
104
101
function display_error (io:: IO , stack:: ExceptionStack )
105
102
printstyled (io, " ERROR: " ; bold= true , color= Base. error_color ())
106
- stack = ExceptionStack ([(exception = x[1 ], backtrace = scrub_repl_backtrace (x[2 ])) for x in stack ])
107
- istrivial = length (stack) == 1 && length (stack[1 ]. backtrace) ≤ 1 # frame 1 = top level
108
- ! istrivial && ccall (:jl_set_global , Cvoid, (Any, Any, Any), Main, :err , stack)
109
103
show_exception_stack (IOContext (io, :limit => true ), stack)
110
104
println (io)
111
105
end
112
106
display_error (stack:: ExceptionStack ) = display_error (stderr , stack)
113
- display_error (er, bt= nothing ) = display_error (stderr , er, bt)
114
107
115
108
function eval_user_input (errio, @nospecialize (ast), show_value:: Bool )
116
109
errcount = 0
@@ -122,6 +115,8 @@ function eval_user_input(errio, @nospecialize(ast), show_value::Bool)
122
115
print (color_normal)
123
116
end
124
117
if lasterr != = nothing
118
+ lasterr = scrub_repl_backtrace (lasterr)
119
+ istrivialerror (lasterr) || ccall (:jl_set_global , Cvoid, (Any, Any, Any), Main, :err , lasterr)
125
120
invokelatest (display_error, errio, lasterr)
126
121
errcount = 0
127
122
lasterr = nothing
@@ -149,6 +144,7 @@ function eval_user_input(errio, @nospecialize(ast), show_value::Bool)
149
144
end
150
145
errcount += 1
151
146
lasterr = current_exceptions ()
147
+ ccall (:jl_set_global , Cvoid, (Any, Any, Any), Main, :err , lasterr)
152
148
if errcount > 2
153
149
@error " It is likely that something important is broken, and Julia will not be able to continue normally" errcount
154
150
break
0 commit comments