Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert serialization errors to string #67

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Malt"
uuid = "36869731-bdee-424d-aa32-cab38c994e3b"
authors = ["Sergio Alejandro Vargas <[email protected]>"]
version = "1.1.0"
version = "1.1.1"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down
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