Documentation
¶
Overview ¶
Package errors provides type-safe error handling for dupl
Index ¶
- Variables
- func HandleMarshalingError(operation, context string, err error) error
- func Is(err error, errorType ErrorType) bool
- func IsDuplError(err error) bool
- func SafeMarshal(v any, context string) ([]byte, error)
- func SafeMarshalIndent(v any, prefix, indent, context string) ([]byte, error)
- func SafeMarshalIndentNilSafe(v any, prefix, indent, nilErrorMessage string) ([]byte, error)
- func SafeMarshalNilSafe(v any, nilErrorMessage string) ([]byte, error)
- func SafeUnmarshal(data []byte, v any, context string) error
- func Wrap(err error, errorType ErrorType, msg string) error
- func WrapConfig(err error, context string) error
- func WrapFile(err error, file, operation string) error
- func WrapIO(err error, file, operation string) error
- func WrapValidation(err error, context string) error
- func Wrapf(err error, errorType ErrorType, format string, args ...any) error
- type DuplError
- type ErrorType
- type MarshalError
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnsupportedValueType = errors.New("unsupported value type") ErrUnsupportedType = errors.New("unsupported type") ErrInvalidUTF8 = errors.New("invalid UTF-8 encoding") )
Pre-defined error formats for static error wrapping.
Functions ¶
func HandleMarshalingError ¶
HandleMarshalingError provides unified JSON marshaling error handling. It inspects the concrete encoding/json/v2 error types (not their message strings, which are unstable) so callers can match the typed sentinels via errors.Is.
In json/v2, UnsupportedValueError and UnsupportedTypeError from v1 are unified into SemanticError. We match on the action field to distinguish marshal-time type incompatibilities from other semantic errors.
func IsDuplError ¶
IsDuplError checks if an error is already a DuplError.
func SafeMarshal ¶
SafeMarshal provides safe marshaling with consistent error handling.
func SafeMarshalIndent ¶
SafeMarshalIndent provides safe indented marshaling with consistent error handling.
func SafeMarshalIndentNilSafe ¶
SafeMarshalIndentNilSafe provides safe indented marshaling with nil check. Returns a validation error if the input is nil.
func SafeMarshalNilSafe ¶
SafeMarshalNilSafe provides safe marshaling with nil check. Returns a validation error if the input is nil.
func SafeUnmarshal ¶
SafeUnmarshal provides safe unmarshaling with consistent error handling.
func Wrap ¶
Wrap wraps an error with additional context using the specified error type. If the cause is already a DuplError, it returns the original error.
func WrapConfig ¶
WrapConfig wraps an error as a ConfigError.
func WrapValidation ¶
WrapValidation wraps an error as a ValidationError.
Types ¶
type DuplError ¶
DuplError is the main error type with rich context.
func NewConfigError ¶
NewConfigError creates a new configuration error.
func NewFileError ¶
NewFileError creates a new file error with context.
func NewIOError ¶
NewIOError creates a new I/O error.
func NewInternalError ¶
NewInternalError creates a new internal error.
func NewValidationError ¶
NewValidationError creates a new validation error.
type MarshalError ¶
MarshalError is a specialized error for JSON marshaling failures.
func (*MarshalError) Error ¶
func (e *MarshalError) Error() string
func (*MarshalError) Unwrap ¶
func (e *MarshalError) Unwrap() error