apperr

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package apperr defines the typed errors used across the CLI, the MCP server and the internal clients, together with the stable mapping from error to process exit code.

Every failure the user can observe is an *Error with a machine-readable Code and a Category. The Category value is the exit code, so the CLI and the MCP server report failures the same way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode returns the exit code for an error: 0 for no error, the category value otherwise.

Types

type Category

type Category int

Category is the class of a failure. Its numeric value is the process exit code the CLI returns for it.

const (
	// Generic is an unclassified failure.
	Generic Category = 1
	// Usage is a bad invocation: unknown flag, invalid value, missing input.
	Usage Category = 2
	// Auth is a missing, expired or rejected session.
	Auth Category = 3
	// NotFound is a missing resource.
	NotFound Category = 4
	// Blocked is a refusal by Repsol, a firewall or a rate limit.
	Blocked Category = 5
	// Network is a transport failure or a timeout on a read.
	Network Category = 6
	// APIChanged means Repsol answered with an unexpected status or shape.
	APIChanged Category = 7
	// Refused means the request was understood but not allowed.
	Refused Category = 8
	// OutcomeUnknown means an order write may or may not have been placed.
	OutcomeUnknown Category = 9
	// Interrupted means the run was cancelled.
	Interrupted Category = 130
)

The error categories, whose values are the CLI exit codes.

func (Category) String

func (c Category) String() string

String returns the snake_case name of the category.

type Error

type Error struct {
	// Category is the class of the failure; its value is the exit code.
	Category Category
	// Code is a snake_case machine code, such as "pending_order".
	Code string
	// Message is a human-readable, single-line description.
	Message string
	// Hint tells the user what to do next. It never contains secrets.
	Hint string
	// HTTPStatus is the status code of the failing response, or 0.
	HTTPStatus int
	// Endpoint is the API path of the failing call, never a full URL.
	Endpoint string
	// Retryable reports whether repeating the call could succeed.
	Retryable bool
	// Err is the wrapped cause, if any.
	Err error
}

Error is a failure with a machine-readable code, a category, an optional hint for the user and the HTTP context of the call that failed.

func From

func From(err error) *Error

From converts any error into an *Error. It returns nil only for a nil error, and it keeps the fields of an error that already is one.

func New

func New(cat Category, code, msg string) *Error

New builds an error of the given category and code.

func (*Error) Error

func (e *Error) Error() string

Error returns the message, followed by the cause when there is one.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped cause.

func (*Error) WithCause

func (e *Error) WithCause(err error) *Error

WithCause sets the cause and returns the same error.

func (*Error) WithHint

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

WithHint sets the hint and returns the same error.

Jump to

Keyboard shortcuts

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