Skip to content

Commit 3535e03

Browse files
authored
Fix world age errors with show(eval_result) (#27)
We use `show` to format the user's evaluation result, but this is done from outside of `eval` so we need to ensure it's running in the latest world.
1 parent b500729 commit 3535e03

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RemoteREPL"
22
uuid = "1bd9f7bb-701c-4338-bec7-ac987af7c555"
33
authors = ["Chris Foster <[email protected]> and contributors"]
4-
version = "0.2.9"
4+
version = "0.2.10"
55

66
[deps]
77
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"

src/server.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ function eval_message(display_properties, messageid, messagebody)
4545
expr = preprocess_expression!(messagebody, io)
4646
result = Main.eval(expr)
4747
if messageid === :eval && !isnothing(result)
48-
show(io, MIME"text/plain"(), result)
48+
# We require invokelatest here in case the user
49+
# modifies any method tables after starting the session,
50+
# which change methods of `show`
51+
Base.invokelatest(show, io, MIME"text/plain"(), result)
4952
end
5053
end
5154
end
@@ -55,7 +58,7 @@ function eval_message(display_properties, messageid, messagebody)
5558
elseif messageid === :help
5659
resultstr = sprint_ctx(display_properties[]) do io
5760
md = Main.eval(REPL.helpmode(io, messagebody))
58-
show(io, MIME"text/plain"(), md)
61+
Base.invokelatest(show, io, MIME"text/plain"(), md)
5962
end
6063
return (:help_result, resultstr)
6164
elseif messageid === :display_properties
@@ -73,7 +76,7 @@ function eval_message(display_properties, messageid, messagebody)
7376
end
7477
catch _
7578
resultstr = sprint_ctx(display_properties[]) do io
76-
Base.display_error(io, Base.catch_stack())
79+
Base.invokelatest(Base.display_error, io, Base.catch_stack())
7780
end
7881
return (:error, resultstr)
7982
end

test/runtests.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ try
141141
# Special case handling of stdout
142142
@test runcommand("println(@remote(stdout), \"hi\")") == "hi\n"
143143

144+
# Issue #26: world age errors showing output
145+
@test runcommand("""
146+
struct A
147+
end
148+
149+
Base.show(io::IO, a::A) = print(io, "Surprise")
150+
151+
A()
152+
""") == "Surprise"
153+
@test occursin("Surprise", runcommand("""
154+
struct MyExc <: Exception
155+
end
156+
157+
Base.showerror(io::IO, e::MyExc) = print(io, "Surprise")
158+
159+
throw(MyExc())
160+
"""))
161+
144162
# Execute a single command on a separate connection
145163
@test (RemoteREPL.remote_eval(test_interface, test_port, "asdf")::Text).content == "42"
146164

0 commit comments

Comments
 (0)