Skip to content

Commit 9c94e7a

Browse files
authored
Restore stacktrace scrubing in fallback REPL. (#59241)
Fixes #59223 by adding intermediary function names to use the same `__repl_entry` prefix.
1 parent f9f6f89 commit 9c94e7a

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

base/client.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ function display_error(io::IO, er, bt)
120120
end
121121
display_error(er, bt=nothing) = display_error(stderr, er, bt)
122122

123+
# N.B.: Any functions starting with __repl_entry cut off backtraces when printing in the REPL.
124+
__repl_entry_client_lower(mod::Module, @nospecialize(ast)) = Meta.lower(mod, ast)
125+
__repl_entry_client_eval(mod::Module, @nospecialize(ast)) = Core.eval(mod, ast)
126+
123127
function eval_user_input(errio, @nospecialize(ast), show_value::Bool)
124128
errcount = 0
125129
lasterr = nothing
@@ -136,8 +140,8 @@ function eval_user_input(errio, @nospecialize(ast), show_value::Bool)
136140
errcount = 0
137141
lasterr = nothing
138142
else
139-
ast = Meta.lower(Main, ast)
140-
value = Core.eval(Main, ast)
143+
ast = __repl_entry_client_lower(Main, ast)
144+
value = __repl_entry_client_eval(Main, ast)
141145
setglobal!(Base.MainInclude, :ans, value)
142146
if !(value === nothing) && show_value
143147
if have_color

test/client.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
import Base.StackTraces: StackFrame
4+
35
nested_error_expr = quote
46
try
57
__not_a_binding__
@@ -57,3 +59,34 @@ end
5759
@test eval(:(ans = 1)) == 1
5860
@test eval(:(err = 1)) == 1
5961
end
62+
63+
@testset "scrub REPL-related frames" begin
64+
repl_bt = [StackFrame(:foo, "foo.jl", 1),
65+
StackFrame(:__repl_entry_anysuffix, "client.jl", 2),
66+
StackFrame(:bar, "bar.jl", 3)]
67+
scrubbed_repl_bt = Base.scrub_repl_backtrace(repl_bt)
68+
69+
nonrepl_bt = [StackFrame(:foo, "foo.jl", 1),
70+
StackFrame(:baz, "baz.jl", 2),
71+
StackFrame(:bar, "bar.jl", 3)]
72+
scrubbed_nonrepl_bt = Base.scrub_repl_backtrace(nonrepl_bt)
73+
74+
@test length(scrubbed_repl_bt) == 1
75+
@test scrubbed_repl_bt[1].func == :foo
76+
@test length(scrubbed_nonrepl_bt) == 3
77+
78+
errio = IOBuffer()
79+
lower_errexpr = :(@bad)
80+
Base.eval_user_input(errio, lower_errexpr, false)
81+
outstr = String(take!(errio))
82+
@test occursin("ERROR: LoadError: UndefVarError: `@bad`", outstr)
83+
@test !occursin("_repl_entry", outstr)
84+
@test !occursin(r"\.[/\\]client.jl", outstr)
85+
86+
errexpr = :(error("fail"))
87+
Base.eval_user_input(errio, errexpr, false)
88+
outstr = String(take!(errio))
89+
@test occursin("ERROR: fail", outstr)
90+
@test !occursin("_repl_entry", outstr)
91+
@test !occursin(r"\.[/\\]client.jl", outstr)
92+
end

0 commit comments

Comments
 (0)