Skip to content

Accumulate all validation errors before reporting #50

Description

@aryasaatvik

Problem

Bunli currently throws on the first validation error. If a user passes --port abc --env invalid, they only see the --port error, fix it, re-run, and then see the --env error. This is a poor CLI experience.

Solution

Validate all options in a command, collect all failures, and report them together:

$ mycli deploy --port abc --env invalid

Error: 2 validation errors in "deploy":
  --port: expected number, got "abc"
  --env: must be one of: dev, staging, prod

Design

  1. New error class in errors.ts:
export class AggregateValidationError extends TaggedError('AggregateValidationError')<{
  message: string
  command: string
  errors: BunliValidationError[]
}>() {}
  1. Refactor parseArgs() in parser.ts:

    • Change validateOption() to return a Result instead of throwing
    • Accumulate all BunliValidationError instances during parsing
    • After all options processed, throw AggregateValidationError if any errors
  2. Update error rendering in cli.ts:

    • renderValidationError() handles AggregateValidationError
    • Display all issues with consistent formatting

Edge cases

  • Repeatable options: one error per option (not per item)
  • Default application failures (trailing loop) must also accumulate
  • mergeProvidedFlags() in execute() path should also accumulate
  • Valid options should still be parsed correctly alongside invalid ones

Files

  • packages/core/src/errors.ts — add AggregateValidationError
  • packages/core/src/parser.ts — refactor for error accumulation
  • packages/core/src/validation.ts — update validateValues() to use structured error
  • packages/core/src/cli.ts — update error rendering
  • packages/core/src/output/serialize.ts — serialize aggregate errors
  • packages/core/src/index.ts — export new error type

Depends on

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions