Overview
Bunli uses thebetter-result library’s TaggedError pattern for type-safe error handling. All errors are strongly typed and carry contextual information for debugging.
Error Pattern
Bunli errors extendTaggedError from the better-result library:
- Type safety: Errors are typed and can be discriminated
- Context: Each error carries structured metadata
- Pattern matching: Use with Result types for functional error handling
Plugin Errors
Defined inpackages/core/src/plugin/errors.ts
PluginLoadError
Thrown when a plugin fails to load.
message: Error descriptionplugin: Name of the plugin that failed to loadcause: Original error that caused the failure
PluginValidationError
Thrown when a plugin fails validation checks.
message: Validation error descriptionplugin: Name of the invalid plugin
PluginHookError
Thrown when a plugin hook execution fails.
message: Error descriptionplugin: Name of the pluginhook: Which hook failed ('setup'or'beforeCommand')cause: Original error
CLI Errors
Defined inpackages/core/src/cli.ts
InvalidConfigError
Thrown when CLI configuration is invalid.
CommandNotFoundError
Thrown when a command cannot be found.
message: Error descriptioncommand: The command name that wasn’t found
CommandExecutionError
Thrown when a command fails during execution.
message: Error descriptioncommand: The command that failedcause: Original error that caused the failure
OptionValidationError
Thrown when an option fails validation.
message: Error descriptioncommand: The command nameoption: The option that failed validationcause: Original validation error
Config Errors
Defined inpackages/core/src/config-loader.ts
ConfigLoadError
Thrown when configuration file fails to load.
ConfigNotFoundError
Thrown when no configuration file is found.
Error Handling Patterns
Pattern 1: Type Narrowing
Useinstanceof to narrow error types:
Pattern 2: Result Types
Use withResult from better-result for functional error handling:
Pattern 3: Error Context
Access structured error context:Creating Custom Errors
For your own CLI, follow the TaggedError pattern:See Also
- Validation API - Validation utilities
- Plugin API - Plugin system
- CLI API - CLI creation and management