1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 04:48:52 -05:00

fix: panic on process.kill() after run (#7405)

This commit fixes panic caused by "unimplemented!()"
calls for some variants of "nix::errno::Errno".

Catch-all variant now returns "Error" class name
instead of panicking.

Co-authored-by: Bert Belder <bertbelder@gmail.com>
This commit is contained in:
Bartek Iwańczuk 2020-09-09 22:40:16 +02:00 committed by GitHub
parent 839c59b14f
commit 2423a867c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View file

@ -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 { fn get_nix_error_class(error: &nix::Error) -> &'static str {
use nix::errno::Errno::*; use nix::errno::Errno::*;
match error { match error {
nix::Error::Sys(EPERM) => "PermissionDenied", nix::Error::Sys(ECHILD) => "NotFound",
nix::Error::Sys(EINVAL) => "TypeError", nix::Error::Sys(EINVAL) => "TypeError",
nix::Error::Sys(ENOENT) => "NotFound", nix::Error::Sys(ENOENT) => "NotFound",
nix::Error::Sys(ENOTTY) => "BadResource", nix::Error::Sys(ENOTTY) => "BadResource",
nix::Error::Sys(UnknownErrno) => unreachable!(), nix::Error::Sys(EPERM) => "PermissionDenied",
nix::Error::Sys(_) => unreachable!(), nix::Error::Sys(ESRCH) => "NotFound",
nix::Error::Sys(UnknownErrno) => "Error",
nix::Error::Sys(_) => "Error",
nix::Error::InvalidPath => "TypeError", nix::Error::InvalidPath => "TypeError",
nix::Error::InvalidUtf8 => "InvalidData", nix::Error::InvalidUtf8 => "InvalidData",
nix::Error::UnsupportedOperation => unreachable!(), nix::Error::UnsupportedOperation => unreachable!(),

View file

@ -375,6 +375,30 @@ unitTest({ perms: { run: true } }, async function runClose(): Promise<void> {
p.stderr.close(); p.stderr.close();
}); });
unitTest(
{ perms: { run: true } },
async function runKillAfterStatus(): Promise<void> {
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 { unitTest(function signalNumbers(): void {
if (Deno.build.os === "darwin") { if (Deno.build.os === "darwin") {
assertEquals(Deno.Signal.SIGSTOP, 17); assertEquals(Deno.Signal.SIGSTOP, 17);