clierr

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package clierr maps the SDK's typed error hierarchy to friendly, actionable CLI messages and stable exit codes, and renders a machine-readable error envelope for --json.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteJSONError

func WriteJSONError(w io.Writer, err error, code ExitCode)

WriteJSONError emits the --json error envelope to w.

Types

type Coded

type Coded struct {
	Msg  string
	Code ExitCode
}

Coded carries a pre-chosen exit code (and an optional message). Commands that render their own output — e.g. a batch summary — return a Coded with an empty Msg so the top-level handler exits with the right code without printing again.

func (*Coded) Error

func (e *Coded) Error() string

type ExitCode

type ExitCode int

ExitCode is a stable, documented process exit status.

const (
	ExitOK          ExitCode = 0
	ExitGeneric     ExitCode = 1
	ExitUsage       ExitCode = 2
	ExitAuth        ExitCode = 3
	ExitQuota       ExitCode = 4
	ExitValidation  ExitCode = 5
	ExitConversion  ExitCode = 6
	ExitTimeout     ExitCode = 7
	ExitNetwork     ExitCode = 8
	ExitInterrupted ExitCode = 130
)

func Classify

func Classify(err error) (string, ExitCode)

Classify turns any error into a user-facing message and its exit code, matching most-specific SDK type first via errors.As.

type UsageError

type UsageError struct{ Err error }

UsageError marks a bad-invocation error (unknown flag, missing/invalid argument) so it maps to ExitUsage rather than a generic failure.

func (*UsageError) Error

func (e *UsageError) Error() string

func (*UsageError) Unwrap

func (e *UsageError) Unwrap() error

Jump to

Keyboard shortcuts

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