Skip to content

The one and only agent harness for complex codebases. Project memory, planning, execution, and verified completion inside Codex.

fix(bin): distinguish ENOENT from other spawn failures in lazycodex-ai

Arvunod40a0cb9c43f
diff --git a/bin/lazycodex-ai.js b/bin/lazycodex-ai.js
index 186178d7..4e9e9742 100755
--- a/bin/lazycodex-ai.js
+++ b/bin/lazycodex-ai.js
@@ -28,7 +28,11 @@ const result = spawnSync("npx", commandArgs, {
})
if (result.error) {
- console.error(result.error.message)
+ if (result.error.code === "ENOENT") {
+ console.error("npx not found on PATH. Install Node.js 20+ from https://nodejs.org.")
+ } else {
+ console.error(result.error.message)
+ }
process.exit(1)
}
diff --git a/test/bin-spawn-error.test.mjs b/test/bin-spawn-error.test.mjs
new file mode 100644
index 00000000..e2a690b4
--- /dev/null
+++ b/test/bin-spawn-error.test.mjs
@@ -0,0 +1,28 @@
+import { describe, it } from "node:test"
+import assert from "node:assert/strict"
+import { execFileSync } from "node:child_process"
+import { fileURLToPath } from "node:url"
+import { dirname, join } from "node:path"
+
+const here = dirname(fileURLToPath(import.meta.url))
+const bin = join(here, "..", "bin", "lazycodex-ai.js")
+
+describe("bin/lazycodex-ai.js spawn error handling", () => {
+ it("prints a clear message and exits 1 when npx is not on PATH", () => {
+ // Force ENOENT by stripping PATH to an empty string for the child.
+ let stderr = ""
+ let code = 0
+ try {
+ execFileSync(process.execPath, [bin, "--help"], {
+ stdio: "pipe",
+ env: { ...process.env, PATH: "" },
+ })
+ } catch (e) {
+ stderr = e.stderr ? e.stderr.toString() : String(e)
+ code = e.status ?? 1
+ }
+ assert.equal(code, 1)
+ assert.match(stderr, /npx not found/, "stderr should mention missing npx")
+ assert.match(stderr, /Node\.js/, "stderr should suggest installing Node.js")
+ })
+})