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.
This commit is contained in:
RRFZ authored and GitHub committed 2026-11-18 23:05:59 +08:00
1 parent c2be327835
commit 390969209d
2 files changed
+50 -1

No files matched your search

+31
View File
@@ -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" },
+19 -1
View File
@@ -20,9 +20,27 @@ const LAUNCH_REFUSALS: Readonly<Record<string, LaunchRefusal["kind"]>> = {
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,
};