diff --git a/cli/errors.rs b/cli/errors.rs index ffa0b95e47..041e8703c7 100644 --- a/cli/errors.rs +++ b/cli/errors.rs @@ -156,12 +156,14 @@ fn get_url_parse_error_class(_error: &url::ParseError) -> &'static str { fn get_nix_error_class(error: &nix::Error) -> &'static str { use nix::errno::Errno::*; match error { - nix::Error::Sys(EPERM) => "PermissionDenied", + nix::Error::Sys(ECHILD) => "NotFound", nix::Error::Sys(EINVAL) => "TypeError", nix::Error::Sys(ENOENT) => "NotFound", nix::Error::Sys(ENOTTY) => "BadResource", - nix::Error::Sys(UnknownErrno) => unreachable!(), - nix::Error::Sys(_) => unreachable!(), + nix::Error::Sys(EPERM) => "PermissionDenied", + nix::Error::Sys(ESRCH) => "NotFound", + nix::Error::Sys(UnknownErrno) => "Error", + nix::Error::Sys(_) => "Error", nix::Error::InvalidPath => "TypeError", nix::Error::InvalidUtf8 => "InvalidData", nix::Error::UnsupportedOperation => unreachable!(), diff --git a/cli/tests/unit/process_test.ts b/cli/tests/unit/process_test.ts index 5b78449707..76b7552955 100644 --- a/cli/tests/unit/process_test.ts +++ b/cli/tests/unit/process_test.ts @@ -375,6 +375,30 @@ unitTest({ perms: { run: true } }, async function runClose(): Promise { p.stderr.close(); }); +unitTest( + { perms: { run: true } }, + async function runKillAfterStatus(): Promise { + const p = Deno.run({ + cmd: ["python", "-c", 'print("hello")'], + }); + await p.status(); + + // On Windows the underlying Rust API returns `ERROR_ACCESS_DENIED`, + // which serves kind of as a catch all error code. More specific + // error codes do exist, e.g. `ERROR_WAIT_NO_CHILDREN`; it's unclear + // why they're not returned. + const expectedErrorType = Deno.build.os === "windows" + ? Deno.errors.PermissionDenied + : Deno.errors.NotFound; + assertThrows( + () => p.kill(Deno.Signal.SIGTERM), + expectedErrorType, + ); + + p.close(); + }, +); + unitTest(function signalNumbers(): void { if (Deno.build.os === "darwin") { assertEquals(Deno.Signal.SIGSTOP, 17);