Documentation ¶
Overview ¶
Package exit defines exit and error behavior of programs and commands.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct { // Exit code of the program (if applicable) ExitCode // Message for this error // Messages should pass docfmt.Validate Message string }
Error represents any error state by a program. It implements the builtin error interface.
The zero value represents that no error occured and is ready to use.
func AsError ¶
AsError asserts that err is either nil or of type Error and returns it. When err is nil, the zero value of type Error is returned.
If err is not nil and not of type Error, calls panic().
func (Error) WithMessage ¶
WithMessage returns a copy of this error with the same Code but different Message.
The new message is the message passed as an argument.
func (Error) WithMessageF ¶
WithMessageF returns a copy of this error with the same Code but different Message. The new message is the current message, formatted using a call to SPrintf and the arguments.
type ExitCode ¶
type ExitCode uint8
ExitCode determines the exit behavior of a program. These are returned as an exit code to the operating system. See ExitCode.Return().
const ( // ExitZero indicates that no error occured. // It is the zero value of type ExitCode. ExitZero ExitCode = 0 // ExitGeneric indicates a generic error occured within this invocation. // This typically implies a subcommand-specific behavior wants to return failure to the caller. ExitGeneric ExitCode = 1 // ExitUnknownCommand indicates that the user attempted to call a subcommand that is not defined. ExitUnknownCommand ExitCode = 2 // ExitGeneralArguments indiciates that the user attempted to pass invalid general arguments to the program. ExitGeneralArguments ExitCode = 3 // ExitCommandArguments indicates that the user attempted to pass invalid command-specific arguments to a subcommand. ExitCommandArguments ExitCode = 4 // ExitPanic indicates that the go code called panic() inside the executation of the current program. // This typically implies a bug inside a program. ExitPanic ExitCode = 255 )