Repository navigation
fix(mitm): remove duplicated 'Command failed:' prefix (#3641) #3662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * Regression test for #3641 — `execFileText` produces a doubled | ||
| * "Command failed: Command failed: ..." prefix in error messages. | ||
| * | ||
| * Node's `execFile` already sets `error.message` to | ||
| * "Command failed: <command>" when the child process exits non-zero. | ||
| * `execFileText` was prepending its own "Command failed: " prefix on top of | ||
| * that, producing the doubled string. | ||
| * | ||
| * The fix: surface `getErrorMessage(error)` directly (Node's message already | ||
| * contains the command), only appending stderr when it is non-empty. | ||
| * | ||
| * Uses `/bin/false` (always exits 1) as the deterministic failing command on | ||
| * Linux/macOS. This is the only case that triggers "Command failed: ..." in | ||
| * Node's error.message (ENOENT from a missing binary uses "spawn ... ENOENT" | ||
| * instead, so it never doubles). | ||
| */ | ||
| import { test } from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { execFileText } from "../../src/mitm/systemCommands.ts"; | ||
|
|
||
| // `/bin/false` exits with code 1 — guaranteed to produce a "Command failed:" | ||
| // error.message from Node's execFile, which is exactly the case that was | ||
| // being doubled by the bug. | ||
| const FALSE_CMD = "/bin/false"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: Regression test is not cross-platform The test hardcodes |
||
|
|
||
| test("execFileText: error message does NOT contain a doubled 'Command failed:' prefix", async () => { | ||
| await assert.rejects( | ||
| () => execFileText(FALSE_CMD, []), | ||
| (err: unknown) => { | ||
| assert.ok(err instanceof Error, "expected an Error"); | ||
| const msg = err.message; | ||
| assert.ok( | ||
| !msg.includes("Command failed: Command failed:"), | ||
| `Error message contains doubled prefix: ${JSON.stringify(msg)}`, | ||
| ); | ||
| return true; | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test("execFileText: error message for a non-zero exit still contains 'Command failed:'", async () => { | ||
| await assert.rejects( | ||
| () => execFileText(FALSE_CMD, []), | ||
| (err: unknown) => { | ||
| assert.ok(err instanceof Error, "expected an Error"); | ||
| // The message should still contain the Node-generated prefix once. | ||
| assert.ok( | ||
| err.message.includes("Command failed:"), | ||
| `Error message should still contain "Command failed:": ${JSON.stringify(err.message)}`, | ||
| ); | ||
| return true; | ||
| }, | ||
| ); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Removing the prefix changes ENOENT error formatting
execFileTextnow rejects with Node's raw ENOENT message (spawn <cmd> ENOENT) instead of the previousCommand failed: spawn <cmd> ENOENT. If callers rely on the prefix for missing binaries, this is an unannounced API-shape change. Consider normalizing only the non-zero-exit path or adding spawn-error coverage if the new shape is intentional.