exitcode

package
v0.4.0-alpha.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func ConfigError(err error) error

ConfigError marks err as a configuration problem (exit status Config).

func Name

func Name(code int) string

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

func UsageError(err error) error

UsageError marks err as a usage error (exit status Usage).

Types

type Classifier

type Classifier func(err error) (status int, code string)

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".

type Error

type Error struct {
	Code int
	Err  error
	// Quiet means the command already wrote its own result document in --json mode, so no error document follows.
	Quiet bool
}

Error is an error that asks for a specific exit status.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL