errors

package
v1.0.48254 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitSuccess        = 0
	ExitGeneralError   = 1
	ExitBadArguments   = 2
	ExitAuthError      = 3
	ExitAPIError       = 4
	ExitNotFound       = 5
	ExitCancelled      = 6
	ExitValidationFail = 7
	ExitTimeout        = 8
)

Exit code constants. Document new codes here before using them. Keep in sync with the exit code table in CLAUDE.md.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLIError

type CLIError struct {
	Code        string   // machine-readable identifier, e.g. "auth.token_missing"
	Title       string   // short label, e.g. "Authentication required"
	Message     string   // full explanation
	Suggestions []string // actionable next steps
	Ref         string   // documentation URL, may be empty
	ExitCode    int      // which exit code to use; defaults to ExitGeneralError
}

CLIError is the structured error type used throughout the CLI. Every error surfaced to the user must carry all fields.

func New

func New(code, title, message string) *CLIError

New constructs a CLIError with ExitGeneralError as the default exit code.

func (*CLIError) Error

func (e *CLIError) Error() string

func (*CLIError) Format

func (e *CLIError) Format() string

Format renders the error for display on stderr. Output is intentionally multi-line so suggestions are readable.

func (*CLIError) FormatJSON

func (e *CLIError) FormatJSON() string

FormatJSON renders the error as a JSON object for stderr when --json is active. Consumers can detect errors by checking for the "error": true field.

func (*CLIError) WithExitCode

func (e *CLIError) WithExitCode(code int) *CLIError

WithExitCode returns a copy of the error with the given exit code.

func (*CLIError) WithRef

func (e *CLIError) WithRef(url string) *CLIError

WithRef returns a copy of the error with a documentation URL.

func (*CLIError) WithSuggestions

func (e *CLIError) WithSuggestions(suggestions ...string) *CLIError

WithSuggestions returns a copy of the error with suggestions appended.

Jump to

Keyboard shortcuts

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