Skip to content

Propagate CLI errors instead of silently swallowing them - #3

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1787594534-error-handling
Open

Propagate CLI errors instead of silently swallowing them#3
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1787594534-error-handling

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Checklist

  • I have read the Contributor Guide
  • I have read and agree to the Code of Conduct
  • I have added a description of my changes and why I'd like them included in the section below

Description of Changes

Every command previously ended by logging a failure and returning normally, so next-quick reported a half-finished project as success and exited 0. Failures are now propagated to a single place that reports them and sets a non-zero exit code.

Root causes fixed:

  • Async plugin installs were never awaited. Plugin.install was typed => void, but kinde and mongoose are async. plugins.kinde.install({}) / plugins.mongoose.install({}) returned a floating promise, so the surrounding try/catch could never see a failure and the command returned before setup finished. install is now => void | Promise<void> and all call sites await it (also in installPlugins, which used forEach + per-plugin catch that continued installing after a failure).
  • .then().catch(console.error) in init and deploy turned any failure into a log line. Both are now plain await inside the command action, and a missing selection throws instead of return-ing.
  • Swallowed I/O. writeToEnv logged and returned when .env.local was missing or unwritable (the Mongo connection string was silently dropped); applyPackageJsonAdditions logged a read/write failure and then printed package.json has been updated; updateEslintConfig returned early leaving Prettier half-configured. These now throw with the failing path in the message.
  • Unchecked execSync. npm install, git init, and npx husky failures surfaced as bare shell noise; they're wrapped with the command that failed.
  • git helpers conflated "not configured" with "git broke". hasRemote() returned false on any error, printing the "add a remote" instructions even when git itself failed. hasUnpushedChanges() used the exit code of git diff --quiet as a signal, so an unrelated git failure read as "you have uncommitted changes"; it now inspects git status --porcelain --untracked-files=no output and throws on failure.
  • User input ignored. The Kinde env-var loop discarded the Done? answer and re-prompted forever until the env file happened to be complete; answering "no" now exits with instructions.
  • Disabled plugins crashed opaquely. A plugin turned off in plugins/config.json was filtered out of the registry, so plugins.kinde.install threw TypeError: undefined. requirePlugin() gives an actionable message.

New utils/errors.ts:

toError(unknown): Error                      // normalize thrown values
withContext('Failed to install plugin x', e) // wrap, keep original message + stack
runCommand(name, () => cmd.execute())        // log via LogLevel.error, set process.exitCode = 1

src/index.ts wraps each program.command(...).action(...) in runCommand and registers unhandledRejection / uncaughtException handlers as a backstop. Remaining console.error calls were switched to log(..., LogLevel.error) for consistent formatting.

Also checkIfAnyDirectoryExists uses readdirSync(cwd, { withFileTypes: true }) instead of a statSync per entry, which threw on broken symlinks in the cwd.

Verified with npx tsc --noEmit, npm run build, eslint, and by running the built CLI: a malformed .nextquickrc now prints ✖ Error: Failed to read /tmp/nqtest/.nextquickrc: ... and exits 1 (previously an unhandled throw). No behavior change on the happy path.

Related Issues

None

Link to Devin session: https://app.devin.ai/sessions/930de6c8667a42399318e34d90a17035
Requested by: @lox-bot

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

1 participant