clierr

package
v0.264.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: 8 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 clierr centralizes how command errors map to user-facing messages and process exit codes, so main can stay a thin shell and every command surfaces failures consistently.

Index

Constants

View Source
const (
	CodeError      = 1   // generic runtime failure
	CodeUsage      = 2   // bad invocation (unknown flag, wrong arg count)
	CodeTestFailed = 3   // `assertions test` ran and some assertions failed
	CodeNetwork    = 4   // could not reach the OpenFGA server
	CodeCanceled   = 130 // interrupted (Ctrl-C); 128 + SIGINT
)

Process exit codes. Scripts and CI can branch on these instead of parsing stderr text.

Variables

This section is empty.

Functions

func Code

func Code(err error) int

Code resolves the exit code for err: an explicit Coded wins, then an interruption maps to CodeCanceled, a bad invocation to CodeUsage, a network failure to CodeNetwork, and anything else to CodeError.

func Friendly

func Friendly(err error) string

Friendly renders err for a human: connection failures get an actionable hint (with the original error kept for detail); everything else is returned as-is.

func IsBrokenPipe

func IsBrokenPipe(err error) bool

IsBrokenPipe reports that the downstream stdout consumer closed its end of a pipe. This is normal shell control flow (for example `ofga ... | head`), not an OpenFGA network failure.

func IsConnErr

func IsConnErr(err error) bool

IsConnErr reports whether err looks like a network-level failure (refused connection, DNS lookup failure, timeout) rather than a normal API error. It checks the idiomatic net.Error interface first, then falls back to matching well-known substrings for errors that don't implement it.

func IsIgnorableBrokenPipe

func IsIgnorableBrokenPipe(err error) bool

IsIgnorableBrokenPipe reports a plain stdout EPIPE that may be treated as a successful short read by a downstream consumer. Explicitly coded failures still win even if an output write also encountered EPIPE.

func IsUsageErr

func IsUsageErr(err error) bool

IsUsageErr reports whether err is one of cobra's flag/argument validation failures, which it returns as plain errors (missing required flag, unknown flag/command, wrong arg count). These are bad invocations, not runtime failures, so they map to CodeUsage and a "--help" hint.

func WithCode

func WithCode(code int, err error) error

WithCode tags err with a specific exit code. Returns nil for a nil error.

Types

type Coded

type Coded struct {
	C   int
	Err error
}

Coded wraps an error with an explicit process exit code.

func (*Coded) Error

func (e *Coded) Error() string

func (*Coded) Unwrap

func (e *Coded) Unwrap() error

Jump to

Keyboard shortcuts

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