Documentation
¶
Overview ¶
Package failure classes errors and maps the classes to the shared exit-code table of contract.md section 9.2. A classed error carries a message, the next step the caller should take, and details for the error envelope the CLI writes on stderr.
Index ¶
- func Code(class Class) int
- func ExitCode(err error) int
- func Is(err error, class Class) bool
- func New(class Class, message, nextStep string, details ...any) error
- func Register(class Class, code int)
- func Wrap(cause error, class Class, message, nextStep string, details ...any) error
- func Write(w io.Writer, err error) error
- type Class
- type Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New makes a classed error. details are key, value pairs for the envelope. It panics on an empty nextStep: every failure tells the caller what to do next.
func Register ¶
Register adds an app class with its exit code. Codes 9 to 125 are the app's; the shared table owns 0 to 8, 130 and 143. It panics on a code outside that range or on a class or code already taken, because the tool's exit codes would then be ambiguous.
Types ¶
type Class ¶
type Class string
Class is the stable failure category. Its string and its code are part of the output contract of every tool.
const ( OK Class = "ok" Internal Class = "internal" Usage Class = "usage" Auth Class = "auth" Permission Class = "permission" NotFound Class = "not_found" Conflict Class = "conflict" Remote Class = "remote" Timeout Class = "timeout" Cancelled Class = "cancelled" Terminated Class = "terminated" )
The shared classes. Every tool gives them the same meaning and the same exit code.