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, };