Skip to content

Commit

Permalink
Fix world age errors with show(eval_result) (#27)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
c42f authored Nov 22, 2021
1 parent b500729 commit 3535e03
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RemoteREPL"
uuid = "1bd9f7bb-701c-4338-bec7-ac987af7c555"
authors = ["Chris Foster <[email protected]> and contributors"]
version = "0.2.9"
version = "0.2.10"

[deps]
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand Down
9 changes: 6 additions & 3 deletions src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ function eval_message(display_properties, messageid, messagebody)
expr = preprocess_expression!(messagebody, io)
result = Main.eval(expr)
if messageid === :eval && !isnothing(result)
show(io, MIME"text/plain"(), result)
# We require invokelatest here in case the user
# modifies any method tables after starting the session,
# which change methods of `show`
Base.invokelatest(show, io, MIME"text/plain"(), result)
end
end
end
Expand All @@ -55,7 +58,7 @@ function eval_message(display_properties, messageid, messagebody)
elseif messageid === :help
resultstr = sprint_ctx(display_properties[]) do io
md = Main.eval(REPL.helpmode(io, messagebody))
show(io, MIME"text/plain"(), md)
Base.invokelatest(show, io, MIME"text/plain"(), md)
end
return (:help_result, resultstr)
elseif messageid === :display_properties
Expand All @@ -73,7 +76,7 @@ function eval_message(display_properties, messageid, messagebody)
end
catch _
resultstr = sprint_ctx(display_properties[]) do io
Base.display_error(io, Base.catch_stack())
Base.invokelatest(Base.display_error, io, Base.catch_stack())
end
return (:error, resultstr)
end
Expand Down
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ try
# Special case handling of stdout
@test runcommand("println(@remote(stdout), \"hi\")") == "hi\n"

# Issue #26: world age errors showing output
@test runcommand("""
struct A
end
Base.show(io::IO, a::A) = print(io, "Surprise")
A()
""") == "Surprise"
@test occursin("Surprise", runcommand("""
struct MyExc <: Exception
end
Base.showerror(io::IO, e::MyExc) = print(io, "Surprise")
throw(MyExc())
"""))

# Execute a single command on a separate connection
@test (RemoteREPL.remote_eval(test_interface, test_port, "asdf")::Text).content == "42"

Expand Down

2 comments on commit 3535e03

@c42f
Copy link
Collaborator Author

@c42f c42f commented on 3535e03 Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/49144

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.10 -m "<description of version>" 3535e039d8744900cdc4e0cdf2ae48aa9dce867a
git push origin v0.2.10

Please sign in to comment.