mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
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:
parent
b358426eea
commit
979d71c883
2 changed files with 48 additions and 48 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue