errors

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorCode

type ErrorCode string

ErrorCode represents a structured error classification.

const (
	// ErrCodeInvalidInput indicates malformed or invalid input.
	ErrCodeInvalidInput ErrorCode = "INVALID_INPUT"
	// ErrCodeNotFound indicates a requested resource was not found.
	ErrCodeNotFound ErrorCode = "NOT_FOUND"
	// ErrCodeIO indicates a file or I/O operation error.
	ErrCodeIO ErrorCode = "IO_ERROR"
	// ErrCodeDatabase indicates a database operation error.
	ErrCodeDatabase ErrorCode = "DATABASE_ERROR"
	// ErrCodeConversion indicates a data conversion or parsing error.
	ErrCodeConversion ErrorCode = "CONVERSION_ERROR"
	// ErrCodeScanner indicates a scanner execution error.
	ErrCodeScanner ErrorCode = "SCANNER_ERROR"
	// ErrCodeTimeout indicates an operation exceeded its time limit.
	ErrCodeTimeout ErrorCode = "TIMEOUT"
	// ErrCodeInternal indicates an internal system error.
	ErrCodeInternal ErrorCode = "INTERNAL"
)

type StructuredError

type StructuredError struct {
	Code    ErrorCode
	Message string
	Cause   error
	Context map[string]any
}

StructuredError provides structured error information for better observability. It includes an error code for programmatic handling, a human-readable message, the underlying cause, and optional context for debugging.

func New

func New(code ErrorCode, message string) *StructuredError

New creates a new StructuredError with the given code and message.

func NewWithContext

func NewWithContext(code ErrorCode, message string, context map[string]any) *StructuredError

NewWithContext creates a new StructuredError with context information.

func Newf

func Newf(code ErrorCode, format string, args ...any) *StructuredError

Newf creates a new StructuredError with a formatted message.

func Wrap

func Wrap(code ErrorCode, message string, cause error) *StructuredError

Wrap wraps an existing error with additional context.

func WrapWithContext

func WrapWithContext(code ErrorCode, message string, cause error, context map[string]any) *StructuredError

WrapWithContext wraps an error with additional context information.

func Wrapf

func Wrapf(code ErrorCode, cause error, format string, args ...any) *StructuredError

Wrapf wraps an error with a formatted message.

func (*StructuredError) Error

func (e *StructuredError) Error() string

Error implements the error interface.

func (*StructuredError) Unwrap

func (e *StructuredError) Unwrap() error

Unwrap returns the underlying cause for errors.Is and errors.As support.

Jump to

Keyboard shortcuts

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