Documentation
¶
Overview ¶
Package exitcode defines the process exit statuses of porthole and portholed, and runs a cobra command tree so that every failure ends in one of them (and, with --json, in an error document on stdout).
Index ¶
Constants ¶
const ( OK = 0 // success General = 1 // any other failure Usage = 2 // wrong flags or arguments Connect = 3 // the server could not be reached Auth = 4 // the server refused the token (unauthorized, token_revoked, token_expired) Rejected = 5 // the server refused a tunnel (name_taken, forbidden, limit_exceeded, port_unavailable) Daemon = 6 // the local daemon is not running, or this user may not use its socket Config = 78 // a configuration problem that restarting cannot fix (sysexits.h EX_CONFIG) )
The exit statuses. docs/client.md and docs/server.md list them for users.
Variables ¶
This section is empty.
Functions ¶
func ConfigError ¶
ConfigError marks err as a configuration problem (exit status Config).
func Name ¶
Name is the "code" of the error document for an exit status that has no more specific code.
func Run ¶
func Run(ctx context.Context, root *cobra.Command, prog string, args []string, classify Classifier) int
Run executes root with args (without the program name) and returns the exit status. A failure is written as "prog: message" to stderr, or, with --json, as an error document to stdout. Any error that happens before a command started running (unknown command, bad flag, wrong number of arguments, a required flag missing) is a usage error. root must have jsonout.AddFlag applied.
func Status ¶
func Status(err error, classify Classifier) int
Status returns the exit status for err: 0 for nil, the Code of an *Error anywhere in the chain, else what classify (may be nil) says, else General.
func UsageError ¶
UsageError marks err as a usage error (exit status Usage).
Types ¶
type Classifier ¶
Classifier maps an error that is not an *Error to an exit status and, optionally, a specific error code for the error document ("" selects Name(status)). A status of 0 or less means "not recognised".