exitcode

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Success          = 0
	General          = 1
	Usage            = 2
	Authentication   = 3
	NotFound         = 4
	PermissionDenied = 5
	RateLimited      = 6
	PartialFailure   = 7
)

Exit codes matching README documentation.

Variables

This section is empty.

Functions

func CodeFrom

func CodeFrom(err error) int

CodeFrom extracts the exit code from an error. If the error contains an *Error anywhere in its chain, that code is returned. Otherwise returns General (1).

func CodeName

func CodeName(code int) string

CodeName returns a short string label for an exit code.

func PartialOrPropagate added in v1.19.0

func PartialOrPropagate(succeeded, failed int, firstErr error, msg string) error

PartialOrPropagate maps a batch tally to an exit error:

  • failed == 0 -> nil
  • succeeded > 0 && failed > 0 -> PartialFailure (7) carrying msg + counts
  • succeeded == 0 && failed > 0-> firstErr's exit code (propagated), or General

Types

type Error

type Error struct {
	Code    int
	Message string
	Err     error          // optional wrapped error
	Hint    string         // optional one-line remediation, surfaced separately
	Details map[string]any // optional structured extras for the JSON envelope
}

Error is an error that carries a specific exit code.

func New

func New(code int, msg string) *Error

New returns a new Error with the given code and message.

func Wrap

func Wrap(code int, err error) *Error

Wrap returns a new Error with the given code wrapping err.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

func (*Error) WithDetails added in v1.19.0

func (e *Error) WithDetails(d map[string]any) *Error

WithDetails attaches structured extras and returns e for chaining.

func (*Error) WithHint added in v1.19.0

func (e *Error) WithHint(hint string) *Error

WithHint attaches a one-line remediation hint and returns e for chaining.

Jump to

Keyboard shortcuts

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