errors

package
v0.8.1 Latest Latest
Warning

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

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

Documentation

Overview

Package errors defines the structured error model used across the CLI.

Every user-facing failure is a *CLIError carrying a Category, a stable Code, a human message, an agent-facing hint and concrete next steps. The category maps deterministically to a process exit code (see codes.go) and to recovery guidance (see hints.go).

This package is shared by the openobserve-cli command layer and is also importable as a library; see the repository README. The Category set, the stable Codes, and their deterministic mapping to exit codes are an agent-facing contract relied on by the CLI and its companion Skill. Add new codes rather than renaming or repurposing existing ones, and keep the category -> exit-code mapping stable.

Index

Constants

View Source
const (
	ExitSuccess    = 0
	ExitInternal   = 1
	ExitUsage      = 2
	ExitConfig     = 3
	ExitAuth       = 4
	ExitPermission = 5
	ExitNotFound   = 6
	ExitRateLimit  = 7
	ExitNetwork    = 8
	ExitServer     = 9
	ExitParse      = 10
	ExitConflict   = 11
)

Exit codes. Each category maps to exactly one code so a calling agent can branch on the process exit status without parsing stderr.

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode returns the process exit code for an error. A nil error yields ExitSuccess; an unclassified error yields ExitInternal.

Types

type CLIError

type CLIError struct {
	Category   Category
	Code       string
	Message    string
	Hint       string
	NextSteps  []string
	Retryable  bool
	HTTPStatus int
	Recovery   *Recovery
	// contains filtered or unexported fields
}

CLIError is the single error type surfaced to the user. It is JSON-encodable (see Payload) and unwraps to any wrapped cause.

func AsCLIError

func AsCLIError(err error) *CLIError

AsCLIError converts any error into a *CLIError, classifying unknown errors as internal. A nil error returns nil.

func New

func New(cat Category, code, message string) *CLIError

New builds a CLIError for the given category. The hint and next steps are filled from the category defaults unless overridden later via the With* helpers.

func Newf

func Newf(cat Category, code, format string, args ...any) *CLIError

Newf is New with a printf-formatted message.

func Wrap

func Wrap(cause error, cat Category, code, message string) *CLIError

Wrap attaches a cause to a freshly built CLIError.

func (*CLIError) Error

func (e *CLIError) Error() string

Error implements the error interface.

func (*CLIError) Payload

func (e *CLIError) Payload() Payload

Payload renders the error as its JSON-encodable form.

func (*CLIError) Unwrap

func (e *CLIError) Unwrap() error

Unwrap exposes the wrapped cause for errors.Is / errors.As.

func (*CLIError) WithCause

func (e *CLIError) WithCause(cause error) *CLIError

WithCause attaches an underlying cause.

func (*CLIError) WithHTTPStatus

func (e *CLIError) WithHTTPStatus(status int) *CLIError

WithHTTPStatus records the originating HTTP status code.

func (*CLIError) WithHint

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

WithHint overrides the hint text.

func (*CLIError) WithNextSteps

func (e *CLIError) WithNextSteps(steps ...string) *CLIError

WithNextSteps overrides the suggested next steps.

func (*CLIError) WithRecovery added in v0.7.0

func (e *CLIError) WithRecovery(recovery Recovery) *CLIError

WithRecovery records a structured recovery action for agent hosts.

type Category

type Category string

Category classifies a failure. It drives both the exit code and the hints.

const (
	CategoryUsage      Category = "usage"
	CategoryConfig     Category = "config"
	CategoryAuth       Category = "auth"
	CategoryPermission Category = "permission"
	CategoryNotFound   Category = "not_found"
	CategoryConflict   Category = "conflict"
	CategoryRateLimit  Category = "rate_limit"
	CategoryNetwork    Category = "network"
	CategoryServer     Category = "server"
	CategoryParse      Category = "parse"
	CategoryInternal   Category = "internal"
)

func FromHTTPStatus

func FromHTTPStatus(status int) Category

FromHTTPStatus classifies an HTTP status code into a Category. Used by the API client to turn non-2xx responses into structured errors.

type Payload

type Payload struct {
	Error PayloadBody `json:"error"`
}

Payload is the JSON shape written to stderr for a failure.

type PayloadBody

type PayloadBody struct {
	Category   Category  `json:"category"`
	Code       string    `json:"code"`
	Message    string    `json:"message"`
	Hint       string    `json:"hint,omitempty"`
	NextSteps  []string  `json:"next_steps,omitempty"`
	Retryable  bool      `json:"retryable"`
	HTTPStatus int       `json:"http_status,omitempty"`
	Recovery   *Recovery `json:"recovery,omitempty"`
}

PayloadBody is the inner object of Payload.

type Recovery added in v0.7.0

type Recovery struct {
	Action   string   `json:"action"`
	Scope    string   `json:"scope"`
	Requires []string `json:"requires,omitempty"`
}

Recovery describes an environment change a caller can make before retrying. It is separate from Retryable: retrying in the same environment may still be pointless when, for example, a sandbox cannot access the user's keychain.

Jump to

Keyboard shortcuts

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