Skip to content

Handle missing dist in CLI bin#44

Open
xianzuyang9-blip wants to merge 2 commits into
subhan-f:mainfrom
xianzuyang9-blip:codex/handle-missing-dist-bin
Open

Handle missing dist in CLI bin#44
xianzuyang9-blip wants to merge 2 commits into
subhan-f:mainfrom
xianzuyang9-blip:codex/handle-missing-dist-bin

Conversation

@xianzuyang9-blip

Copy link
Copy Markdown

Summary

  • catch startup failures from bin/excod.cjs when dist/cli.js has not been built
  • print a direct recovery hint telling contributors to run npm run build
  • add a regression test for the missing-dist path

Fixes #6.

Validation

  • npm test
  • npm run build
  • npm run lint
  • Manual check: temporarily move dist/, run node bin/excod.cjs, confirm it exits 1 with the build hint

@qodo-code-review

qodo-code-review Bot commented Jun 7, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0)

Grey Divider


Action required

1. Catch masks real errors ✓ Resolved 🐞 Bug ≡ Correctness
Description
bin/excod.cjs reports “dist/cli.js not found” for any import-time failure (including runtime errors
thrown while executing the CLI), and only prints error.message, which can mislead debugging and hide
stack traces.
Code

bin/excod.cjs[R2-6]

+import('../dist/cli.js').catch((error) => {
+  console.error('Error: dist/cli.js not found. Run `npm run build` first.');
+  console.error(error.message);
+  process.exit(1);
+});
Evidence
The bin wrapper prints a fixed not-found message and exits for any rejection, while the CLI module
executes immediately on import, so runtime failures during CLI execution are also routed through
this handler and misreported.

bin/excod.cjs[1-6]
src/cli.ts[15-30]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`bin/excod.cjs` currently catches *all* dynamic-import failures and prints a fixed “dist/cli.js not found” recovery hint. This will misreport genuine runtime failures inside the CLI (e.g., exceptions during command parsing/execution) as a missing build artifact, and it also drops stack traces by logging only `error.message`.

### Issue Context
Importing the CLI module executes the program immediately (`await program.parseAsync()`), so any runtime error during CLI execution will reject the import promise and hit this catch handler.

### Fix Focus Areas
- bin/excod.cjs[1-6]
- src/cli.ts[15-30]

### Suggested change
1. In `bin/excod.cjs`, detect the specific missing-module case (e.g., `error?.code === 'ERR_MODULE_NOT_FOUND'` and message/specifier indicates `dist/cli.js`). Only then print the build hint.
2. For all other errors, print a generic “CLI startup failed” message and log `error.stack ?? error` so stack traces are preserved; then exit non-zero.
3. (Optional) Add a regression test covering a non-`ERR_MODULE_NOT_FOUND` failure path to ensure it does not print the build hint.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Brittle dist rename test ✓ Resolved 🐞 Bug ☼ Reliability
Description
tests/bin.test.ts renames the real dist/ directory to a hard-coded dist-test-backup, which will
throw if that backup already exists (e.g., after an interrupted run) and makes the test depend on
mutating the working tree.
Code

tests/bin.test.ts[R7-10]

+    const distExists = existsSync('dist');
+    if (distExists) {
+      renameSync('dist', 'dist-test-backup');
+    }
Evidence
The test renames dist to a fixed dist-test-backup name without checking for an existing
destination, and later renames it back, making the test sensitive to leftover state.

tests/bin.test.ts[6-24]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The test simulates a missing `dist/` by renaming the project’s real `dist` directory to `dist-test-backup`. This is brittle because `renameSync` fails if the destination already exists, and it mutates the working tree in a way that can leave the repo in a bad state if the run is interrupted.

### Issue Context
The code under test resolves `../dist/cli.js` relative to `bin/excod.cjs`, so you can test the missing-dist behavior by running a *copied* `bin/excod.cjs` from a temporary directory that intentionally has no `dist/`.

### Fix Focus Areas
- tests/bin.test.ts[1-26]

### Suggested change
1. Create a temporary directory (e.g., `mkdtempSync(join(tmpdir(), 'excod-test-'))`).
2. Create a `bin/` subdirectory inside it and copy `bin/excod.cjs` there.
3. Spawn `node <temp>/bin/excod.cjs` with `cwd` set to the temp dir (no `dist/` created).
4. Assert exit code and stderr contents as you already do.
This removes the need to rename the real `dist/` and eliminates the hard-coded backup-name collision.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

Review Summary by Qodo

Handle missing dist in CLI bin with recovery hint

🐞 Bug fix 🧪 Tests

Grey Divider

Walkthroughs

Description
• Catch startup failures when dist/cli.js missing
• Print recovery hint directing users to run npm run build
• Add regression test for missing dist scenario
Diagram
flowchart LR
  bin["bin/excod.cjs"] -->|import dist/cli.js| catch["catch error handler"]
  catch -->|missing dist| error["print recovery hint"]
  error -->|exit 1| process["process exit"]
  test["tests/bin.test.ts"] -->|verify| behavior["error behavior"]

Loading

Grey Divider

File Changes

1. bin/excod.cjs Error handling +5/-1

Add error handling for missing dist/cli.js

• Wrap dynamic import with .catch() error handler
• Print user-friendly error message with recovery instructions
• Exit process with status code 1 on failure
• Include original error message for debugging

bin/excod.cjs


2. tests/bin.test.ts 🧪 Tests +26/-0

Add regression test for missing dist scenario

• Create new test file for bin/excod.cjs entry point
• Temporarily rename dist directory to simulate missing build
• Verify exit status is 1 and error message contains recovery hint
• Restore dist directory after test completion

tests/bin.test.ts


Grey Divider

Qodo Logo

Comment thread bin/excod.cjs
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.

BUG-05: bin/excod.cjs has no error handling for missing dist/

1 participant