Skip to content

fix(core): show errors thrown by validators as the validation message - #658

Open
ronavkarumsi04 wants to merge 1 commit into
bombshell-dev:mainfrom
ronavkarumsi04:fix/catch-thrown-validator-errors
Open

ronavkarumsi04 wants to merge 1 commit into
bombshell-dev:mainfrom
ronavkarumsi04:fix/catch-thrown-validator-errors

Conversation

@ronavkarumsi04

Copy link
Copy Markdown

What does this PR do?

A validate function that throws (or an async one that rejects) currently escapes Prompt's keypress handler and crashes the CLI. This wraps the validation call in Prompt in a try/catch and treats the thrown value as the validation problem: an Error shows its message, anything else is stringified. The prompt then enters the normal error state so the user can fix their input.

Because date and path route their validate through the core Prompt, they get the same behaviour.

Adds two tests in packages/core/test/prompts/prompt.test.ts (sync throw and async rejection) that fail without the change, plus a patch changeset for @clack/core.

Closes #597

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

Copilot AI balanced review requested due to automatic review settings December 3, 2026 18:46
@changeset-bot

changeset-bot Bot commented Dec 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 571aef6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@clack/core Patch
@clack/prompts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

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.

Consider catching thrown errors from validators

2 participants