errors

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package errors provides typed errors with meaningful exit codes. AI Agents use exit codes to programmatically handle errors without parsing error messages.

Index

Constants

View Source
const (
	ExitSuccess    = 0 // Operation completed successfully
	ExitGeneral    = 1 // Unspecified error
	ExitUsage      = 2 // Invalid arguments or usage error
	ExitAuth       = 3 // Authentication failure (missing/invalid API key)
	ExitNotFound   = 4 // Requested resource not found
	ExitRateLimit  = 5 // API rate limit exceeded
	ExitNetwork    = 6 // Network connectivity error
	ExitPermission = 7 // Insufficient permissions
)

Exit codes — each maps to a specific error category.

View Source
const (
	CodeGeneral    = "GENERAL_ERROR"
	CodeUsage      = "USAGE_ERROR"
	CodeAuth       = "AUTH_ERROR"
	CodeNotFound   = "NOT_FOUND"
	CodeRateLimit  = "RATE_LIMITED"
	CodeNetwork    = "NETWORK_ERROR"
	CodePermission = "PERMISSION_DENIED"
)

Error code strings used in JSON error responses.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLIError

type CLIError struct {
	ExitCode int
	Code     string
	Message  string
	Err      error
}

CLIError is a typed error that carries an exit code and error code string.

func New

func New(exitCode int, code string, message string) *CLIError

New creates a CLIError with the given exit code, code string, and message.

func NewAuthError

func NewAuthError(message string) *CLIError

func NewGeneralError

func NewGeneralError(message string, err error) *CLIError

func NewNetworkError

func NewNetworkError(message string, err error) *CLIError

func NewNotFoundError

func NewNotFoundError(message string) *CLIError

func NewPermissionError

func NewPermissionError(message string) *CLIError

func NewRateLimitError

func NewRateLimitError(message string) *CLIError

func NewUsageError

func NewUsageError(message string) *CLIError

func Wrap

func Wrap(exitCode int, code string, message string, err error) *CLIError

Wrap creates a CLIError wrapping an existing error.

func (*CLIError) Error

func (e *CLIError) Error() string

func (*CLIError) Unwrap

func (e *CLIError) Unwrap() error

Jump to

Keyboard shortcuts

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