Skip to content

Commit fc33413

Browse files
authored
Convert serialization errors to string (#67)
* Convert serialization errors to string * Update Project.toml
1 parent 34e6226 commit fc33413

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Malt"
22
uuid = "36869731-bdee-424d-aa32-cab38c994e3b"
33
authors = ["Sergio Alejandro Vargas <[email protected]>"]
4-
version = "1.1.0"
4+
version = "1.1.1"
55

66
[deps]
77
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"

src/worker.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ function serve(server::Sockets.TCPServer)
7575
msg_id = read(io, MsgID)
7676

7777
msg_data, success = try
78-
deserialize(io), true
78+
(deserialize(io), true)
7979
catch err
80-
err, false
80+
(format_error(err, catch_backtrace()), false)
8181
finally
8282
_discard_until_boundary(io)
8383
end
@@ -116,16 +116,14 @@ function handle(::Val{MsgType.from_host_call_with_response}, socket, msg, msg_id
116116
f, args, kwargs, respond_with_nothing = msg
117117

118118
@async begin
119-
success, result = try
119+
result, success = try
120120
result = f(args...; kwargs...)
121121

122122
# @debug("WORKER: Evaluated result", result)
123-
(true, respond_with_nothing ? nothing : result)
124-
catch e
123+
(respond_with_nothing ? nothing : result, true)
124+
catch err
125125
# @debug("WORKER: Got exception!", e)
126-
(false, sprint() do io
127-
Base.invokelatest(showerror, io, e, catch_backtrace())
128-
end)
126+
(format_error(err, catch_backtrace()), false)
129127
end
130128

131129
_serialize_msg(
@@ -158,9 +156,12 @@ function handle(::Val{MsgType.special_serialization_failure}, socket, msg, msg_i
158156
)
159157
end
160158

159+
format_error(err, bt) = sprint() do io
160+
Base.invokelatest(showerror, io, err, bt)
161+
end
162+
161163
const _channel_cache = Dict{UInt64, AbstractChannel}()
162164

163165
if abspath(PROGRAM_FILE) == @__FILE__
164166
main()
165167
end
166-

test/exceptions.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ macro catcherror(ex)
1313
end
1414
end
1515

16+
# To test serialization
17+
struct LocalStruct end
18+
1619
# @testset "Exceptions" begin
1720
@testset "Exceptions: $W" for W in (
1821
m.DistributedStdlibWorker,
@@ -132,6 +135,12 @@ end
132135
@test m.remote_call_fetch(&, w, true, true)
133136
end
134137

138+
W === m.Worker && @testset "Serialization error" begin
139+
@test_throws m.RemoteException m.remote_eval_fetch(w, quote
140+
$(LocalStruct)()
141+
end)
142+
end
143+
135144
# The worker should be able to handle all that throwing
136145
@test m.isrunning(w)
137146

0 commit comments

Comments
 (0)