Help us shape the future of Go! Take the 2026 Go Developer Survey

exitcode

package
v0.1.2 Latest Latest
Warning

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

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

Documentation

Overview

Package exitcode defines the process exit contract shared by every command.

The contract is intentionally strict so scripts and agents can branch on the exit code instead of parsing stderr:

0  success
1  business failure (API envelope code is not 0/200)
2  usage or configuration error (nothing was sent)
3  runtime failure (network, timeout, 5xx, malformed response)

The API envelope is still written to stdout for 1, so `... | jq .code` keeps working.

Index

Constants

View Source
const (
	OK       = 0
	Business = 1
	Usage    = 2
	Runtime  = 3
)

Variables

This section is empty.

Functions

func Businessf

func Businessf(format string, args ...any) error

Businessf reports an API-level failure that has already been rendered.

func CodeOf

func CodeOf(err error) int

CodeOf returns the exit code carried by err, or Runtime for unknown errors.

func IsQuiet

func IsQuiet(err error) bool

IsQuiet reports whether the error should be printed to stderr.

func New

func New(code int, err error) error

New builds an exit-code error.

func Runtimef

func Runtimef(format string, args ...any) error

Runtimef reports an environmental failure: network, timeout, 5xx.

func Usagef

func Usagef(format string, args ...any) error

Usagef reports a caller mistake: bad flag, missing required field, bad JSON.

Types

type Error

type Error struct {
	Code int
	Err  error
	// Quiet suppresses the "Error: ..." line on stderr. Business failures use
	// it because the envelope on stdout is already the machine-readable error.
	Quiet bool
}

Error wraps an error with the exit code the process should use.

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