diff --git a/src/Malt.jl b/src/Malt.jl index 043392e..8e91d61 100644 --- a/src/Malt.jl +++ b/src/Malt.jl @@ -103,11 +103,18 @@ mutable struct Worker <: AbstractWorker function Worker(; env=String[], exeflags=[]) # Spawn process cmd = _get_worker_cmd(; env, exeflags) - proc = open(Cmd( - cmd; - detach=true, - windows_hide=true, - ), "w+") + err = Pipe() + proc = open( + pipeline( + Cmd( + cmd; + detach=true, + windows_hide=true, + ), + stderr = err + ), + "w+" + ) # Keep internal list __iNtErNaL_get_running_procs() @@ -115,7 +122,14 @@ mutable struct Worker <: AbstractWorker # Block until reading the port number of the process (from its stdout) port_str = readline(proc) - port = parse(UInt16, port_str) + port = tryparse(UInt16, port_str) + if port === nothing + Base.kill(proc, Base.SIGTERM) + close(err.in) + err_t = Threads.@spawn read(err, String) + err_output = fetch(err_t) + error("""Failed to start worker process correctly. Expected to read port from stdout, got "$port_str" instead. Stderr output was:\n$err_output""") + end # Connect socket = Sockets.connect(port) diff --git a/test/exceptions.jl b/test/exceptions.jl index 98c4dc8..ea29828 100644 --- a/test/exceptions.jl +++ b/test/exceptions.jl @@ -147,3 +147,8 @@ struct LocalStruct end m.stop(w) @test !m.isrunning(w) end + +@testset "Failure to spin up Worker" begin + e = @catcherror Malt.Worker(; exeflags = ["-t invalid"]) + @test occursin("ERROR: julia: -t", e.msg) +end