Skip to content

Commit

Permalink
make error mapping more precise and the test more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Sep 9, 2020
1 parent 94ac53e commit 5de058c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cli/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ 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(EPERM) => "PermissionDenied",
nix::Error::Sys(ESRCH) => "NotFound",
nix::Error::Sys(UnknownErrno) => "Error",
nix::Error::Sys(_) => "Error",
nix::Error::InvalidPath => "TypeError",
Expand Down
10 changes: 9 additions & 1 deletion cli/tests/unit/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,16 @@ unitTest(
});
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.SIGQUIT),
() => p.kill(Deno.Signal.SIGTERM),
expectedErrorType,
);

p.close();
Expand Down

0 comments on commit 5de058c

Please sign in to comment.