refactor: ParseError can carry an exit code

Reinstated use of ParseError for all error paths so as to retain existing semantics.
This commit is contained in:
Alec Thomas
2025-03-11 17:32:24 +11:00
parent a86adbbb25
commit 3d03233b16
2 changed files with 19 additions and 13 deletions
+8 -2
View File
@@ -5,11 +5,17 @@ package kong
// It contains the parse Context that triggered the error.
type ParseError struct {
error
Context *Context
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 { return exitUsageError }
func (p *ParseError) ExitCode() int {
if p.exitCode == 0 {
return exitNotOk
}
return p.exitCode
}