errors

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package errors provides custom error types for the CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

As wraps stderrors.As.

func ExitCode

func ExitCode(err error) int

ExitCode returns the exit code for the given error.

Types

type Category

type Category string

Category represents the error category.

const (
	// CategoryValidation represents validation errors.
	CategoryValidation Category = "validation"
	// CategoryAuth represents authentication errors.
	CategoryAuth Category = "auth"
	// CategoryAPI represents API errors.
	CategoryAPI Category = "api"
	// CategoryNetwork represents network errors.
	CategoryNetwork Category = "network"
	// CategoryInternal represents internal errors.
	CategoryInternal Category = "internal"
	// CategoryTimeout represents timeout errors.
	CategoryTimeout Category = "timeout"
	// CategoryRateLimit represents rate limit errors.
	CategoryRateLimit Category = "rate_limit"
)

type Error

type Error struct {
	Category  Category `json:"category"`
	Message   string   `json:"message"`
	Hint      string   `json:"hint,omitempty"`
	Actions   []string `json:"actions,omitempty"`
	Retryable bool     `json:"retryable"`
	RequestID string   `json:"request_id,omitempty"`
	Cause     error    `json:"-"`
}

Error is a custom error type with additional context.

func NewAPI

func NewAPI(message string, opts ...Option) *Error

NewAPI creates a new API error.

func NewAuth

func NewAuth(message string, opts ...Option) *Error

NewAuth creates a new authentication error.

func NewInternal

func NewInternal(message string, opts ...Option) *Error

NewInternal creates a new internal error.

func NewNetwork

func NewNetwork(message string, opts ...Option) *Error

NewNetwork creates a new network error.

func NewRateLimit

func NewRateLimit(message string, opts ...Option) *Error

NewRateLimit creates a new rate limit error.

func NewTimeout

func NewTimeout(message string, opts ...Option) *Error

NewTimeout creates a new timeout error.

func NewValidation

func NewValidation(message string, opts ...Option) *Error

NewValidation creates a new validation error.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying error.

type Option

type Option func(*Error)

Option is a functional option for configuring errors.

func WithActions

func WithActions(actions ...string) Option

WithActions adds suggested actions to the error.

func WithCause

func WithCause(cause error) Option

WithCause sets the underlying cause of the error.

func WithHint

func WithHint(hint string) Option

WithHint adds a hint to the error.

func WithRequestID

func WithRequestID(id string) Option

WithRequestID adds a request ID to the error.

func WithRetryable

func WithRetryable(retryable bool) Option

WithRetryable sets whether the error is retryable.

Jump to

Keyboard shortcuts

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