@@ -493,8 +493,18 @@ $(TYPEDSIGNATURES)
493493function Base. wait (process:: SshProcess )
494494 try
495495 wait (process. _task)
496- catch ex
497- if process. cmd isa Cmd && ! process. cmd. ignorestatus
496+ catch task_ex
497+ ex = process. _task. exception
498+
499+ # The idea is that SshProcessFailedException's and LibSSHException's are
500+ # somewhat expected so we always unwrap them from the
501+ # TaskFailedException before throwing, which is a slightly nicer API to
502+ # work with.
503+ if ex isa SshProcessFailedException || ex isa LibSSHException
504+ if ! (process. cmd isa Cmd && process. cmd. ignorestatus)
505+ throw (process. _task. exception)
506+ end
507+ else
498508 rethrow ()
499509 end
500510 end
@@ -591,6 +601,8 @@ An easy way of getting around these restrictions is to pass the command as a
591601# Throws
592602- [`SshProcessFailedException`](@ref): if the command fails and `ignorestatus()`
593603 wasn't used.
604+ - [`LibSSHException`](@ref): if running the command fails for some other
605+ reason.
594606
595607# Arguments
596608- `cmd`: The command to run. This will be converted to a string for running
@@ -652,10 +664,10 @@ function Base.run(cmd::Union{Cmd, String}, session::Session;
652664 set_channel_callbacks (process. _sshchan, callbacks)
653665
654666 process. _task = Threads. @spawn _exec_command (process)
655- errormonitor (process . _task)
667+
656668 if wait
657669 # Note the use of Base.wait() to avoid aliasing with the `wait` argument
658- Base. wait (process. _task )
670+ Base. wait (process)
659671
660672 if print_out
661673 print (String (copy (process. out)))
0 commit comments