From 5a28d70e05d9854102e983a4c4fd1cf4238361dc Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Mon, 4 Mar 2024 22:05:44 +0530 Subject: [PATCH] fix(node): errno property when command missing (#22691) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/denoland/deno/issues/22604 `remix dev` with Node adapter works: ``` $ ~/gh/littledivy/deno/target/debug/deno task dev Task dev remix dev --manual 💿 remix dev info building... info built (619ms) [remix-serve] http://localhost:3000 (http://192.168.1.24:3000) GET / 200 - - 3.090 ms ``` --- ext/node/polyfills/internal/child_process.ts | 6 +++++- tests/unit_node/child_process_test.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ext/node/polyfills/internal/child_process.ts b/ext/node/polyfills/internal/child_process.ts index 62de6a098d..5a9212618d 100644 --- a/ext/node/polyfills/internal/child_process.ts +++ b/ext/node/polyfills/internal/child_process.ts @@ -275,7 +275,11 @@ export class ChildProcess extends EventEmitter { }); })(); } catch (err) { - this.#_handleError(err); + let e = err; + if (e instanceof Deno.errors.NotFound) { + e = _createSpawnSyncError("ENOENT", command, args); + } + this.#_handleError(e); } } diff --git a/tests/unit_node/child_process_test.ts b/tests/unit_node/child_process_test.ts index 9c6fed9e4f..85bb6d3b09 100644 --- a/tests/unit_node/child_process_test.ts +++ b/tests/unit_node/child_process_test.ts @@ -771,3 +771,15 @@ Deno.test(async function execFileWithUndefinedTimeout() { ); await promise; }); + +Deno.test(async function spawnCommandNotFoundErrno() { + const { promise, resolve } = Promise.withResolvers(); + const cp = CP.spawn("no-such-command"); + cp.on("error", (err) => { + const errno = Deno.build.os === "windows" ? -4058 : -2; + // @ts-ignore: errno missing from typings + assertEquals(err.errno, errno); + resolve(); + }); + await promise; +});