From adc74f47c0da80b286dafa3f407730f10a70067e Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sat, 1 Jun 2024 21:24:45 +0200 Subject: [PATCH] Fix panic when spawning a program that does not exist --- crates/lune-std-process/src/lib.rs | 5 +---- crates/lune/src/tests.rs | 1 + tests/process/spawn/no_panic.luau | 7 +++++++ 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 tests/process/spawn/no_panic.luau diff --git a/crates/lune-std-process/src/lib.rs b/crates/lune-std-process/src/lib.rs index adc4eb8..d3fd502 100644 --- a/crates/lune-std-process/src/lib.rs +++ b/crates/lune-std-process/src/lib.rs @@ -145,10 +145,7 @@ async fn process_spawn( lua: &Lua, (program, args, options): (String, Option>, ProcessSpawnOptions), ) -> LuaResult { - let res = lua - .spawn(spawn_command(program, args, options)) - .await - .expect("Failed to receive result of spawned process"); + let res = lua.spawn(spawn_command(program, args, options)).await?; /* NOTE: If an exit code was not given by the child process, diff --git a/crates/lune/src/tests.rs b/crates/lune/src/tests.rs index ae599da..de726ce 100644 --- a/crates/lune/src/tests.rs +++ b/crates/lune/src/tests.rs @@ -140,6 +140,7 @@ create_tests! { process_spawn_async: "process/spawn/async", process_spawn_basic: "process/spawn/basic", process_spawn_cwd: "process/spawn/cwd", + process_spawn_no_panic: "process/spawn/no_panic", process_spawn_shell: "process/spawn/shell", process_spawn_stdin: "process/spawn/stdin", process_spawn_stdio: "process/spawn/stdio", diff --git a/tests/process/spawn/no_panic.luau b/tests/process/spawn/no_panic.luau new file mode 100644 index 0000000..3a57a9b --- /dev/null +++ b/tests/process/spawn/no_panic.luau @@ -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")