mirror of
https://github.com/denoland/deno.git
synced 2025-03-10 06:07:03 -04:00
fix(runtime): print process name in case of spawn error (#19855)
Fix https://github.com/denoland/deno/issues/19400 Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
This commit is contained in:
parent
7892655d61
commit
624526ae85
2 changed files with 30 additions and 3 deletions
|
@ -885,3 +885,19 @@ Deno.test(
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Deno.test(
|
||||||
|
"process that fails to spawn, prints its name in error",
|
||||||
|
async () => {
|
||||||
|
assertThrows(
|
||||||
|
() => new Deno.Command("doesntexist").outputSync(),
|
||||||
|
Error,
|
||||||
|
"Failed to spawn: doesntexist",
|
||||||
|
);
|
||||||
|
await assertRejects(
|
||||||
|
async () => await new Deno.Command("doesntexist").output(),
|
||||||
|
Error,
|
||||||
|
"Failed to spawn: doesntexist",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use super::check_unstable;
|
use super::check_unstable;
|
||||||
use crate::permissions::PermissionsContainer;
|
use crate::permissions::PermissionsContainer;
|
||||||
|
use deno_core::anyhow::Context;
|
||||||
use deno_core::error::type_error;
|
use deno_core::error::type_error;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
|
@ -285,7 +286,12 @@ fn spawn_child(
|
||||||
// We want to kill child when it's closed
|
// We want to kill child when it's closed
|
||||||
command.kill_on_drop(true);
|
command.kill_on_drop(true);
|
||||||
|
|
||||||
let mut child = command.spawn()?;
|
let mut child = command.spawn().with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Failed to spawn: {}",
|
||||||
|
command.as_std().get_program().to_string_lossy()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
let pid = child.id().expect("Process ID should be set.");
|
let pid = child.id().expect("Process ID should be set.");
|
||||||
|
|
||||||
let stdin_rid = child
|
let stdin_rid = child
|
||||||
|
@ -352,8 +358,13 @@ fn op_spawn_sync(
|
||||||
) -> Result<SpawnOutput, AnyError> {
|
) -> Result<SpawnOutput, AnyError> {
|
||||||
let stdout = matches!(args.stdio.stdout, Stdio::Piped);
|
let stdout = matches!(args.stdio.stdout, Stdio::Piped);
|
||||||
let stderr = matches!(args.stdio.stderr, Stdio::Piped);
|
let stderr = matches!(args.stdio.stderr, Stdio::Piped);
|
||||||
let output =
|
let mut command = create_command(state, args, "Deno.Command().outputSync()")?;
|
||||||
create_command(state, args, "Deno.Command().outputSync()")?.output()?;
|
let output = command.output().with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Failed to spawn: {}",
|
||||||
|
command.get_program().to_string_lossy()
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(SpawnOutput {
|
Ok(SpawnOutput {
|
||||||
status: output.status.try_into()?,
|
status: output.status.try_into()?,
|
||||||
|
|
Loading…
Add table
Reference in a new issue