errors

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package errors provides the AppError type used throughout invgate-cli for structured error handling with HTTP status codes, verbose context, and stdlib errors.Is/As compatibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatError

func FormatError(err error, verbose bool) string

FormatError renders an AppError for stderr output. When verbose is true the Verbose map is appended.

func IsCode

func IsCode(err error, code int) bool

IsCode reports whether err is (or wraps) an AppError with the given code.

Types

type AppError

type AppError struct {
	Code    int            // HTTP status code (0 for non-HTTP errors)
	Message string         // User-facing message
	Cause   error          // Wrapped underlying error (supports errors.Unwrap)
	Verbose map[string]any // Extra context printed only with --verbose
}

AppError is the canonical error type carrying an HTTP status code, a human-readable message, an optional wrapped cause, and a verbose context map printed only when --verbose is active.

func Errorf

func Errorf(format string, args ...any) *AppError

Errorf creates an AppError using fmt.Errorf-style formatting.

func New

func New(msg string) *AppError

New creates a plain AppError with no code (code=0).

func NewError

func NewError(code int, msg string) *AppError

NewError creates an AppError with the given code and message.

func Wrap

func Wrap(err error, code int, msg string) *AppError

Wrap creates an AppError wrapping cause with the given code and message.

func (*AppError) Error

func (e *AppError) Error() string

Error implements the error interface.

func (*AppError) Is

func (e *AppError) Is(target error) bool

Is implements errors.Is so that AppError values match on identity.

func (*AppError) Unwrap

func (e *AppError) Unwrap() error

Unwrap returns the wrapped cause so errors.Is and errors.As traverse the error chain.

func (*AppError) VerboseOutput

func (e *AppError) VerboseOutput() string

VerboseOutput renders the verbose context as a multi-line string. Keys are sorted alphabetically for deterministic output.

Jump to

Keyboard shortcuts

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