Fix panic when spawning a program that does not exist

This commit is contained in:
Filip Tibell 2024-06-01 21:24:45 +02:00
parent 1fd17ca0b3
commit adc74f47c0
No known key found for this signature in database
3 changed files with 9 additions and 4 deletions

View file

@ -145,10 +145,7 @@ async fn process_spawn(
lua: &Lua, lua: &Lua,
(program, args, options): (String, Option<Vec<String>>, ProcessSpawnOptions), (program, args, options): (String, Option<Vec<String>>, ProcessSpawnOptions),
) -> LuaResult<LuaTable> { ) -> LuaResult<LuaTable> {
let res = lua let res = lua.spawn(spawn_command(program, args, options)).await?;
.spawn(spawn_command(program, args, options))
.await
.expect("Failed to receive result of spawned process");
/* /*
NOTE: If an exit code was not given by the child process, NOTE: If an exit code was not given by the child process,

View file

@ -140,6 +140,7 @@ create_tests! {
process_spawn_async: "process/spawn/async", process_spawn_async: "process/spawn/async",
process_spawn_basic: "process/spawn/basic", process_spawn_basic: "process/spawn/basic",
process_spawn_cwd: "process/spawn/cwd", process_spawn_cwd: "process/spawn/cwd",
process_spawn_no_panic: "process/spawn/no_panic",
process_spawn_shell: "process/spawn/shell", process_spawn_shell: "process/spawn/shell",
process_spawn_stdin: "process/spawn/stdin", process_spawn_stdin: "process/spawn/stdin",
process_spawn_stdio: "process/spawn/stdio", process_spawn_stdio: "process/spawn/stdio",

View file

@ -0,0 +1,7 @@
local process = require("@lune/process")
-- Spawning a child process for a non-existent
-- program should not panic, but should error
local success = pcall(process.spawn, "someProgramThatDoesNotExist")
assert(not success, "Spawned a non-existent program")