This works:
julia> @sync @spawnat 2 error("hi")
ERROR: On worker 2:
hi
Stacktrace:
[1] error
@ ./error.jl:33
[2] #51
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/macros.jl:87
[3] #103
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/process_messages.jl:274
[4] run_work_thunk
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/process_messages.jl:63
[5] run_work_thunk
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/process_messages.jl:72
[6] #96
@ ./task.jl:406
Stacktrace:
[1] sync_end(c::Channel{Any})
@ Base ./task.jl:364
[2] top-level scope
@ task.jl:383
The remote error is forwarded to the calling process.
This doesn’t:
julia> @sync @spawnat 2 @sync @async error("hi")
ERROR: On worker 2:
TaskFailedException
nested task error:
Stacktrace:
[1] sync_end
@ ./task.jl:364
[2] macro expansion
@ ./task.jl:383 [inlined]
[3] #47
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/macros.jl:87
[4] #103
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/process_messages.jl:274
[5] run_work_thunk
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/process_messages.jl:63
[6] run_work_thunk
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/process_messages.jl:72
[7] #96
@ ./task.jl:406
Stacktrace:
[1] sync_end(c::Channel{Any})
@ Base ./task.jl:364
[2] top-level scope
@ task.jl:383
Adding the extra @sync @async
seems to mask the original error. This is a contrived example where the @sync @async
is unnecessary, but in the real case I want to run asynchronous tasks on a remote worker. Somehow the errors are not being propagated.
This is what happens if I throw this error on my local process instead of on a remote one:
julia> @sync @async error("hi")
ERROR: TaskFailedException
nested task error: hi
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] (::var"#45#46")()
@ Main ./task.jl:406
Stacktrace:
[1] sync_end(c::Channel{Any})
@ Base ./task.jl:364
[2] top-level scope
@ task.jl:383
While the original error type is not displayed, the error message is.