refactor: make Process#kill() throw sensible errors on Windows (#9111)

Previously, calling `Process#kill()` after the process had exited would
sometimes throw a `TypeError` on Windows. After this patch, it will
throw `NotFound` instead, just like other platforms.

This patch also fixes flakiness of the `runKillAfterStatus` test on
Windows.
This commit is contained in:
Bert Belder 2021-01-13 20:52:12 -08:00
parent b358426eea
commit 979d71c883
2 changed files with 48 additions and 48 deletions

View file

@ -434,16 +434,20 @@ 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.SIGTERM),
expectedErrorType,
let error = null;
try {
p.kill(Deno.Signal.SIGTERM);
} catch (e) {
error = e;
}
assert(
error instanceof Deno.errors.NotFound ||
// On Windows, the underlying Windows API may return
// `ERROR_ACCESS_DENIED` when the process has exited, but hasn't been
// completely cleaned up yet and its `pid` is still valid.
(Deno.build.os === "windows" &&
error instanceof Deno.errors.PermissionDenied),
);
p.close();