From 29fdd5dc4ba929b82edefa383aa918692b73a222 Mon Sep 17 00:00:00 2001 From: Julius Krumbiegel Date: Thu, 19 Sep 2024 13:34:35 +0200 Subject: [PATCH 1/2] Catch failure to open Worker and write out port --- src/Malt.jl | 26 ++++++++++++++++++++------ test/exceptions.jl | 5 +++++ 2 files changed, 25 insertions(+), 6 deletions(-) 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 From 7329df546b866200b2ab0e83e88a08c1bc898fb5 Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Thu, 3 Oct 2024 21:48:19 +0200 Subject: [PATCH 2/2] Update test/exceptions.jl --- test/exceptions.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/exceptions.jl b/test/exceptions.jl index ea29828..5325ca9 100644 --- a/test/exceptions.jl +++ b/test/exceptions.jl @@ -149,6 +149,6 @@ struct LocalStruct end end @testset "Failure to spin up Worker" begin - e = @catcherror Malt.Worker(; exeflags = ["-t invalid"]) + e = @catcherror m.Worker(; exeflags = ["-t invalid"]) @test occursin("ERROR: julia: -t", e.msg) end