Skip to content

Commit b0b7b38

Browse files
fix(server): detect localized Windows command errors (#2152)
Co-authored-by: macroscopeapp[bot] <170038800+macroscopeapp[bot]@users.noreply.github.com>
1 parent fd3b96b commit b0b7b38

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

apps/server/src/processRunner.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from "vitest";
22

3-
import { runProcess } from "./processRunner.ts";
3+
import { isWindowsCommandNotFound, runProcess } from "./processRunner.ts";
44

55
describe("runProcess", () => {
66
it("fails when output exceeds max buffer in default mode", async () => {
@@ -21,3 +21,21 @@ describe("runProcess", () => {
2121
expect(result.stderrTruncated).toBe(false);
2222
});
2323
});
24+
25+
describe("isWindowsCommandNotFound", () => {
26+
it("matches the localized German cmd.exe error text", () => {
27+
const originalPlatform = process.platform;
28+
Object.defineProperty(process, "platform", { value: "win32", configurable: true });
29+
30+
try {
31+
expect(
32+
isWindowsCommandNotFound(
33+
1,
34+
"wird nicht als interner oder externer Befehl, betriebsfahiges Programm oder Batch-Datei erkannt",
35+
),
36+
).toBe(true);
37+
} finally {
38+
Object.defineProperty(process, "platform", { value: originalPlatform, configurable: true });
39+
}
40+
});
41+
});

apps/server/src/processRunner.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,23 @@ function normalizeSpawnError(command: string, args: readonly string[], error: un
3737
return new Error(`Failed to run ${commandLabel(command, args)}: ${error.message}`);
3838
}
3939

40+
const WINDOWS_COMMAND_NOT_FOUND_PATTERNS = [
41+
/is not recognized as an internal or external command/i,
42+
/n.o . reconhecido como um comando interno/i,
43+
/non . riconosciuto come comando interno o esterno/i,
44+
/n.est pas reconnu en tant que commande interne/i,
45+
/no se reconoce como un comando interno o externo/i,
46+
/wird nicht als interner oder externer befehl/i,
47+
] as const;
48+
49+
function hasWindowsCommandNotFoundMessage(output: string): boolean {
50+
return WINDOWS_COMMAND_NOT_FOUND_PATTERNS.some((pattern) => pattern.test(output));
51+
}
52+
4053
export function isWindowsCommandNotFound(code: number | null, stderr: string): boolean {
4154
if (process.platform !== "win32") return false;
4255
if (code === 9009) return true;
43-
return /is not recognized as an internal or external command/i.test(stderr);
56+
return hasWindowsCommandNotFoundMessage(stderr);
4457
}
4558

4659
function normalizeExitError(

0 commit comments

Comments
 (0)