Skip to content

fix(bin): distinguish ENOENT from other spawn failures#23

Merged
code-yeongyu merged 1 commit into
code-yeongyu:mainfrom
Arvuno:fix/bin-spawn-enoent-classification
Jun 5, 2026
Merged

fix(bin): distinguish ENOENT from other spawn failures#23
code-yeongyu merged 1 commit into
code-yeongyu:mainfrom
Arvuno:fix/bin-spawn-enoent-classification

Conversation

@Arvuno
Copy link
Copy Markdown
Contributor

@Arvuno Arvuno commented Jun 5, 2026

Problem

bin/lazycodex-ai.js shells out to npx via spawnSync. When the user's PATH is missing npx (no Node.js installed, or a sandboxed environment that strips npx), the existing code prints the raw syscall error and exits 1. The error gives no hint that the actual problem is a missing npx, and no hint about what to do (install Node.js).

What changed

  • Branch on result.error.code === "ENOENT" in bin/lazycodex-ai.js and print "npx not found on PATH. Install Node.js 20+ from https://nodejs.org." in that case.
  • All other spawn errors fall through to the existing result.error.message print.
  • Added test/bin-spawn-error.test.mjs to assert the new behavior. Test runs the bin with PATH="" to force ENOENT, captures stderr, and asserts the message mentions npx and Node.js. Test passes locally with node --test test/*.test.mjs.

Why this fits

Tiny, focused, no behavior change for valid input. Matches the style of the existing bin script (no external deps, plain Node).

Test

$ node --test test/*.test.mjs
ok 1 - bin/lazycodex-ai.js spawn error handling
# tests 1
# pass 1
# fail 0

Manual:

$ PATH= node bin/lazycodex-ai.js --help
npx not found on PATH. Install Node.js 20+ from https://nodejs.org.

No related issue — this is a clear UX gap observed by running the bin in a fresh container.


Summary by cubic

Improve bin error message when npx is not on PATH by detecting ENOENT and guiding users to install Node.js 20+. Adds a test to verify the behavior.

  • Bug Fixes
    • Detect ENOENT from spawnSync and print "npx not found on PATH. Install Node.js 20+ from https://nodejs.org."; other errors stay the same.
    • Add test/bin-spawn-error.test.mjs to run with empty PATH, asserting the message and exit code 1.

Written for commit d40a0cb. Summary will update on new commits.

Review in cubic

When the user's PATH is missing `npx` (Node.js not installed or
npx-only PATH stripped), the bin script used to print a generic
syscall error like "spawnSync npx ENOENT" with no hint about what
to do.

Branch on `err.code === "ENOENT"` to print a clear message pointing
at the Node.js install page, and leave all other error codes on the
existing syscall message.

Adds a test (test/bin-spawn-error.test.mjs) that runs the bin with
PATH=empty and asserts the new stderr text.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@code-yeongyu code-yeongyu merged commit 584bf29 into code-yeongyu:main Jun 5, 2026
2 checks passed
@code-yeongyu
Copy link
Copy Markdown
Owner

code-yeongyu commented Jun 5, 2026

Verified the PR-specific test locally with node --test test/bin-spawn-error.test.mjs and confirmed GitGuardian + Cubic were PASS. Merged with a merge commit and deleted the branch. Thanks.

@Arvuno
Copy link
Copy Markdown
Contributor Author

Arvuno commented Jun 5, 2026

Thanks for the careful review and the merge, @code-yeongyu 🙌

If you run into a similar spawnSync ENOENT vs "command not found" ambiguity elsewhere in the CLI, this pattern (out.includes('ENOENT')CodexNotFoundError, else CodexExecError) generalizes cleanly — happy to follow up with a second PR if it shows up in another code path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants