Files
Alec Thomas 3d03233b16 refactor: ParseError can carry an exit code
Reinstated use of ParseError for all error paths so as to retain existing semantics.
2025-03-11 17:32:24 +11:00

22 lines
501 B
Go

package kong
// ParseError is the error type returned by Kong.Parse().
//
// It contains the parse Context that triggered the error.
type ParseError struct {
error
Context *Context
exitCode int
}
// Unwrap returns the original cause of the error.
func (p *ParseError) Unwrap() error { return p.error }
// ExitCode returns the status that Kong should exit with if it fails with a ParseError.
func (p *ParseError) ExitCode() int {
if p.exitCode == 0 {
return exitNotOk
}
return p.exitCode
}