From 390969209d18a019af8cf2cd1d3f54f2be1dbe90 Mon Sep 17 00:00:00 2001 From: RRFZ <247457381+Plastic-time@users.noreply.github.com> Date: Wed, 18 Nov 2026 10:05:59 -0500 Subject: [PATCH] fix(process): classify a Windows launch of a non-image file as not executable (#11735) A tool selection that points at a file Windows cannot start (a DLL, a script, any non-PE file) was reported as "could not be launched (ERR_REA_WINDOWS_NATIVE)" by the owned launcher, and as an unrecognised EFTYPE failure by Node's spawn. POSIX reports the same mistake as ENOEXEC: "exists but could not be executed". Treat EFTYPE as not executable, and read the native launcher's ERROR_BAD_EXE_FORMAT (Win32 193) as EFTYPE, the code Node's own spawn reports for the same file. Other native codes stay unclassified. --- src/process/launchFailure.test.ts | 31 +++++++++++++++++++++++++++++++ src/process/launchFailure.ts | 20 +++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/process/launchFailure.test.ts b/src/process/launchFailure.test.ts index f25113cb17..9cee79e4db 100644 --- a/src/process/launchFailure.test.ts +++ b/src/process/launchFailure.test.ts @@ -6,6 +6,7 @@ it.each([ ["ELOOP", { kind: "missing", code: "ELOOP" }], ["ENAMETOOLONG", { kind: "missing", code: "ENAMETOOLONG" }], ["ENOEXEC", { kind: "not_executable", code: "ENOEXEC" }], + ["EFTYPE", { kind: "not_executable", code: "EFTYPE" }], ["EISDIR", { kind: "not_executable", code: "EISDIR" }], ["EPERM", { kind: "not_executable", code: "EPERM" }], ["ENOMEM", { kind: "host-exhausted", code: "ENOMEM", resource: "memory" }], @@ -54,6 +55,36 @@ it.each([ syscall: undefined, }, ], + [ + "Windows native launcher bad image", + { + code: "ERR_REA_WINDOWS_NATIVE", + win32Code: 193, + constraint: "Create process atomically inside owned Job Object failed", + requestedPath: "C:\\tools\\tool.dll", + }, + { + kind: "not_executable", + code: "EFTYPE", + executable: "C:\\tools\\tool.dll", + syscall: undefined, + }, + ], + [ + "Windows native launcher other code", + { + code: "ERR_REA_WINDOWS_NATIVE", + win32Code: 216, + constraint: "Create process atomically inside owned Job Object failed", + requestedPath: "C:\\tools\\tool.exe", + }, + { + kind: "failed", + code: "ERR_REA_WINDOWS_NATIVE", + executable: "C:\\tools\\tool.exe", + syscall: undefined, + }, + ], [ "bare Node spawn", { code: "ENOTDIR", syscall: "spawn" }, diff --git a/src/process/launchFailure.ts b/src/process/launchFailure.ts index 3d00cd2601..d5ff2bd699 100644 --- a/src/process/launchFailure.ts +++ b/src/process/launchFailure.ts @@ -20,9 +20,27 @@ const LAUNCH_REFUSALS: Readonly> = { EACCES: "not_executable", EPERM: "not_executable", ENOEXEC: "not_executable", + // Node on Windows (libuv) reports ERROR_BAD_EXE_FORMAT as EFTYPE. + EFTYPE: "not_executable", EISDIR: "not_executable", }; +/** The native launcher's Win32 code for a file that is not a runnable image. */ +const ERROR_BAD_EXE_FORMAT = 193; + +/** + * The errno of a launch failure. The Windows native launcher names only + * file-not-found and access-denied as errno; its ERROR_BAD_EXE_FORMAT + * becomes EFTYPE, as Node's own spawn reports the same file. + */ +const launchErrnoOf = (cause: Error): unknown => { + const code = Reflect.get(cause, "code"); + return code === "ERR_REA_WINDOWS_NATIVE" && + Reflect.get(cause, "win32Code") === ERROR_BAD_EXE_FORMAT + ? "EFTYPE" + : code; +}; + /** The host resource a launch could not obtain. */ export type LaunchExhaustedResource = | "processes" @@ -158,7 +176,7 @@ export const launcherFailureOf = ( if (identity === undefined) return undefined; const syscall = Reflect.get(cause, "syscall"); return { - ...classifyLaunchErrno(Reflect.get(cause, "code")), + ...classifyLaunchErrno(launchErrnoOf(cause)), ...identity, syscall: typeof syscall === "string" ? syscall : undefined, };