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
- New error class in
errors.ts:
export class AggregateValidationError extends TaggedError('AggregateValidationError')<{
message: string
command: string
errors: BunliValidationError[]
}>() {}
-
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
-
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
Problem
Bunli currently throws on the first validation error. If a user passes
--port abc --env invalid, they only see the--porterror, fix it, re-run, and then see the--enverror. This is a poor CLI experience.Solution
Validate all options in a command, collect all failures, and report them together:
Design
errors.ts:Refactor
parseArgs()inparser.ts:validateOption()to return aResultinstead of throwingBunliValidationErrorinstances during parsingAggregateValidationErrorif any errorsUpdate error rendering in
cli.ts:renderValidationError()handlesAggregateValidationErrorEdge cases
mergeProvidedFlags()inexecute()path should also accumulateFiles
packages/core/src/errors.ts— addAggregateValidationErrorpackages/core/src/parser.ts— refactor for error accumulationpackages/core/src/validation.ts— updatevalidateValues()to use structured errorpackages/core/src/cli.ts— update error renderingpackages/core/src/output/serialize.ts— serialize aggregate errorspackages/core/src/index.ts— export new error typeDepends on