# Error propagation with remote asynchronous tasks seems broken

**URL:** https://discourse.julialang.org/t/error-propagation-with-remote-asynchronous-tasks-seems-broken/58489
**Category:** General Usage
**Tags:** question, error, distributed, task
**Created:** [April 3, 2021, 10:40am UTC](https://discourse.julialang.org/t/error-propagation-with-remote-asynchronous-tasks-seems-broken/58489 "2021-04-03T10:40:19Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [April 3, 2021, 10:40am UTC](https://discourse.julialang.org/t/error-propagation-with-remote-asynchronous-tasks-seems-broken/58489/1 "2021-04-03T10:40:19Z")

</div>

This works:

```julia
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
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
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.
