Skip to content

Commit 4e2e931

Browse files
SaschaMannStefanKarpinski
authored andcommitted
Add more descriptive error to run(``) (Fixes #19094, PR #19118)
1 parent 02b6b0f commit 4e2e931

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

base/process.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ function setup_stdio(anon::Function, stdio::StdIOSet)
507507
end
508508

509509
function spawn(cmd::Cmd, stdios::StdIOSet; chain::Nullable{ProcessChain}=Nullable{ProcessChain}())
510+
if isempty(cmd.exec)
511+
throw(ArgumentError("cannot spawn empty command"))
512+
end
510513
loop = eventloop()
511514
pp = Process(cmd, C_NULL, stdios[1], stdios[2], stdios[3])
512515
setup_stdio(stdios) do in, out, err

test/spawn.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,17 @@ end
406406
@test Base.AndCmds(`$echo abc`, `$echo def`) == Base.AndCmds(`$echo abc`, `$echo def`)
407407
@test Base.AndCmds(`$echo abc`, `$echo def`) != Base.AndCmds(`$echo abc`, `$echo xyz`)
408408

409+
# test for correct error when an empty command is spawned (Issue 19094)
410+
@test_throws ArgumentError run(Base.Cmd(``))
411+
@test_throws ArgumentError run(Base.AndCmds(``, ``))
412+
@test_throws ArgumentError run(Base.AndCmds(``, `$echo test`))
413+
@test_throws ArgumentError run(Base.AndCmds(`$echo test`, ``))
414+
415+
@test_throws ArgumentError spawn(Base.Cmd(``))
416+
@test_throws ArgumentError spawn(Base.AndCmds(``, ``))
417+
@test_throws ArgumentError spawn(Base.AndCmds(``, `$echo test`))
418+
@test_throws ArgumentError spawn(Base.AndCmds(`$echo test`, ``))
419+
409420
# tests for reducing over collection of Cmd
410421
@test_throws ArgumentError reduce(&, Base.AbstractCmd[])
411422
@test_throws ArgumentError reduce(&, Base.Cmd[])

0 commit comments

Comments
 (0)