6 Commits

Author SHA1 Message Date
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
Bob Lail a86adbbb25 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`
2025-03-11 17:21:09 +11:00
Denis Titusov 89b2806f6a Switch to the standard errors API, that was introduced in 1.13 (#273)
* Switch to the standard errors API, that was introduced in 1.13

* Fix linter errors 🤦‍

* Remove withStackError

* fix: freeze go version to 1.17, since 1.18 introduced generics, which are not supported by linters yet

* fix: freeze go version to 1.17, since 1.18 introduced generics, which are not supported by linters yet
2022-03-18 18:54:29 +11:00
Alec Thomas 097bba54ec Revert UsageOnMissing.
This was breaking UsageOnMissing() when combined with validation of
positional arguments, in that it was allowing positional arguments to be
omitted. It also broke UsageOnMissing() somehow so that it did not work.
2020-10-27 17:33:46 +11:00
hasheddan a062611ecf Do not run parent node on missing child err with usageOnMissing option
Refactors usageOnMissing option to not run parent commands after
printing usage when a child node is missing.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-10-20 09:44:46 +11:00
Alec Thomas cdcdf49f67 Display usage information on error. 2018-06-21 10:08:01 +10:00