Skip to content

Commit

Permalink
Convert serialization errors to string (#67)
Browse files Browse the repository at this point in the history
* Convert serialization errors to string

* Update Project.toml
  • Loading branch information
Pangoraw authored Nov 25, 2023
1 parent 34e6226 commit fc33413
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
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

2 comments on commit fc33413

@Pangoraw
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@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/95946

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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 v1.1.1 -m "<description of version>" fc334130d9da2e2dfbf6f70451d46885f535cf4b
git push origin v1.1.1

Please sign in to comment.