Repository navigation
fix: make init overwrite guard intentional (explicit ExitPromptError + non-TTY handling) - #48
Conversation
The init overwrite guard wrapped the config existence check and the confirm prompt in one try block with an empty catch, so ExitPromptError (prompt force-closed, e.g. Ctrl+C) was swallowed and init silently fell through to overwriting the existing config. - Existence check now catches only ENOENT; any other access error surfaces instead of falling through to a write. - Non-interactive sessions (stdin not a TTY) are handled explicitly: refuse to overwrite with a clear message instead of leaving the inquirer prompt pending until the process drains out. - ExitPromptError is handled by name (sibling pattern: remove-project / edit-project / remove-learning): print Cancelled and return cleanly; every other prompt error rethrows. Adds src/commands/__tests__/init.test.ts: cancelled prompt and non-TTY EOF (config untouched, clean exit), fresh generation without prompting, --yes overwrite, and unexpected prompt errors surfacing without overwrite.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Review: APPROVEReviewed the diff against merge-base Live-verified, not assumed: re-ran the sanctioned single-file suite in the worktree — What the fix does right
The four review asks
🟢 F1 — LOW · Introduced · non-blocking — no
|
Summary
Fixes the
projex initoverwrite guard. The guard wrapped both the configexistence check and the confirm prompt in one
trywith an emptycatch, soExitPromptError(prompt force-closed, e.g. Ctrl+C) was silently swallowedand init fell through to overwriting the existing
projex.config.ts.Changes
ENOENT); any otheraccess()error now surfaces instead of falling through to a write.stdinis not a TTY (e.g. stdin from/dev/null), init now explicitly refuses to overwrite and exits cleanlywith a clear message. Previously
@inquirer/confirmleft the promptpromise pending and the process drained out mid-prompt — the "file
untouched" outcome was incidental, never an intentional return.
ExitPromptErrorhandling — matches the sibling pattern(
remove-project,edit-project,remove-learning): catch by name,print
✖ Cancelled., return cleanly. Every other prompt error rethrows(error output / non-zero exit). No error path can silently fall through
to an overwrite.
Tests
New
packages/core/src/commands/__tests__/init.test.ts(6 cases, followingthe sibling test mocking pattern — the prompt is mocked and rejects with an
ErrornamedExitPromptError):--yeswith existing config → overwrites without promptingVerification
pnpm install && pnpm build && pnpm typecheck && pnpm lint && pnpm test—all green (64 test files / 1043 tests).
pnpm --dir packages/core exec vitest run src/commands/__tests__/init.test.ts— 6 passed (6).init < /dev/nullwith an existing config → exit 0, explicit"refusing to overwrite in a non-interactive session" message, file
untouched
✖ Cancelled., exit 0, fileuntouched
✖ Init cancelled., exit 0, fileuntouched
y→ overwrites as intended, exit 0Closes #41