Skip to content

Commit

Permalink
Convert serialization errors to string
Browse files Browse the repository at this point in the history
  • Loading branch information
Pangoraw committed Nov 24, 2023
1 parent 34e6226 commit fb85ab3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/worker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ function serve(server::Sockets.TCPServer)
msg_id = read(io, MsgID)

msg_data, success = try
deserialize(io), true
(deserialize(io), true)
catch err
err, false
(format_error(err, catch_backtrace()), false)
finally
_discard_until_boundary(io)
end
Expand Down Expand Up @@ -116,16 +116,14 @@ function handle(::Val{MsgType.from_host_call_with_response}, socket, msg, msg_id
f, args, kwargs, respond_with_nothing = msg

@async begin
success, result = try
result, success = try
result = f(args...; kwargs...)

# @debug("WORKER: Evaluated result", result)
(true, respond_with_nothing ? nothing : result)
catch e
(respond_with_nothing ? nothing : result, true)
catch err
# @debug("WORKER: Got exception!", e)
(false, sprint() do io
Base.invokelatest(showerror, io, e, catch_backtrace())
end)
(format_error(err, catch_backtrace()), false)
end

_serialize_msg(
Expand Down Expand Up @@ -158,9 +156,12 @@ function handle(::Val{MsgType.special_serialization_failure}, socket, msg, msg_i
)
end

format_error(err, bt) = sprint() do io
Base.invokelatest(showerror, io, err, bt)
end

const _channel_cache = Dict{UInt64, AbstractChannel}()

if abspath(PROGRAM_FILE) == @__FILE__
main()
end

9 changes: 9 additions & 0 deletions test/exceptions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ macro catcherror(ex)
end
end

# To test serialization
struct LocalStruct end

# @testset "Exceptions" begin
@testset "Exceptions: $W" for W in (
m.DistributedStdlibWorker,
Expand Down Expand Up @@ -132,6 +135,12 @@ end
@test m.remote_call_fetch(&, w, true, true)
end

W === m.Worker && @testset "Serialization error" begin
@test_throws m.RemoteException m.remote_eval_fetch(w, quote
$(LocalStruct)()
end)
end

# The worker should be able to handle all that throwing
@test m.isrunning(w)

Expand Down

0 comments on commit fb85ab3

Please sign in to comment.