Documentation
¶
Index ¶
- type ErrorCode
- type StructuredError
- func New(code ErrorCode, message string) *StructuredError
- func NewWithContext(code ErrorCode, message string, context map[string]any) *StructuredError
- func Newf(code ErrorCode, format string, args ...any) *StructuredError
- func Wrap(code ErrorCode, message string, cause error) *StructuredError
- func WrapWithContext(code ErrorCode, message string, cause error, context map[string]any) *StructuredError
- func Wrapf(code ErrorCode, cause error, format string, args ...any) *StructuredError
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 ¶
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.