feat: Allow Kong to exit with semantic exit codes (#507)
* feat: Allow Kong to exit with semantic exit codes At Block, we've instrumented a number of commandline tools and set SLOs on some tools' reliability. To do that effectively, we had to partition usage errors from reliability issues. We looked at [prior art](https://github.com/square/exit?tab=readme-ov-file#reserved-codes-and-prior-art) and, taking inspiration from HTTP, defined [a set of semantic exit codes](https://github.com/square/exit?tab=readme-ov-file#about) in ranges: 80-99 for user errors, 100-119 for system errors. We've been wrapping errors in `exit.Error` at whatever level of the stack can tell which class an error is and unwrapping them at exit (`os.Exit(exit.FromError(err))`). This adds support for semantic exit codes to Kong, to `FatalIfErrorf`, which is used internally by `kong.Parse` and often used in Kong applications. * feat: Exit 80 (Usage Error) when usage is syntactically or semantically invalid * refactor: Always exit 80 (Usage Error) on a `ParseError` but don't wrap errors from hooks in `ParseError`
This commit is contained in:
@@ -10,3 +10,6 @@ type ParseError struct {
|
||||
|
||||
// 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 }
|
||||
|
||||
Reference in New Issue
Block a user