Documentation
¶
Overview ¶
Package exit defines semantic exit codes which may be used by Command Line tools to aid in debugging and instrumentation.
This package defines exit codes in two ranges. Exit Codes 80-99 indicate a user error of some sort. Exit Codes 100-119 indicate software or system error of some sort.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotOK = Error{Code: NotOK} ErrUsageError = Error{Code: UsageError} ErrUnknownSubcommand = Error{Code: UnknownSubcommand} ErrRequirementNotMet = Error{Code: RequirementNotMet} ErrForbidden = Error{Code: Forbidden} ErrMovedPermanently = Error{Code: MovedPermanently} ErrInternalError = Error{Code: InternalError} )
Functions ¶
func IsSignal ¶
IsSignal reports whether an exit code is derived from a signal. It returns true if the code is in the range 128-255 and false if not. It also returns true if the code is -1 because ProcessState.ExitCode() may return -1 if the process was terminated by a signal.
func IsSoftwareError ¶
IsSoftwareError reports whether an exit code is a software error. It returns true if the code is in the range 100-119 and false if not.
func IsUserError ¶
IsUserError reports whether an exit code is a user error. It returns true if the code is in the range 80-99 and false if not.
Types ¶
type Code ¶
type Code = int
Code is the exit code that is passed to the system call `exit` when the program terminates. Conventionally, the value zero indicates success and all other values (1-255) indicate failure.
const ( // UsageError indicates that the program exited unsuccessfully // because it was used incorrectly. // // Examples: a required argument was omitted or an invalid value // was supplied for a flag. UsageError Code = 80 // UnknownSubcommand indicates that the program exited unsuccessfully // because an unrecognized subcommand was invoked. // // This is intended for CLI multi-tools. When you run a command that // doesn't exist from the shell, the shell exits 127. This is distinct // from that value in that the command itself exists but the subcommand // does not (e.g. `git nope` could exit 81). UnknownSubcommand Code = 81 // RequirementNotMet indicates that the program exited unsuccessfully // because a precondition wasn't satisfied. // // Examples: the user must be on a VPN before using the program or have // a minimum version of some other software installed. RequirementNotMet Code = 82 // Forbidden indicates that the program exited unsuccessfully // because the user isn't authorized to perform the requested action. Forbidden Code = 83 // MovedPermanently indicates that the program exited unsuccessfully // because it has been migrated to a new location. MovedPermanently Code = 84 )
Exit Codes 80-99 are reserved for user errors.
const ( // InternalError indicates that the program exited unsuccessfully // because of a problem in its own code. // // Used instead of 1 when the problem is known to be with the program's // code or dependencies. InternalError Code = 100 // because a service it depends on was not available. // // Examples: A local daemon or remote service did not respond, a connection // was closed unexpectedly, an HTTP service responded with 503. Unavailable Code = 101 )
Exit Codes 100-119 are reserved for software or system errors.
func FromSignal ¶
FromSignal returns the exit code that corresponds to when a program exits in response to a signal.