Documentation
¶
Overview ¶
Package errors provides type-safe error handling for dupl
Index ¶
- func HandleMarshalingError(operation, context string, err error) error
- func Is(err error, errorType ErrorType) 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
- func NewAnalysisError(msg string, cause error) *DuplError
- func NewCancelledError(msg string, cause error) *DuplError
- func NewConfigError(msg string, cause error) *DuplError
- func NewDetectionError(msg string, cause error) *DuplError
- func NewFileError(file, msg string, cause error) *DuplError
- func NewIOError(file, msg string, cause error) *DuplError
- func NewInternalError(msg string, cause error) *DuplError
- func NewParseError(file string, line int, msg string, cause error) *DuplError
- func NewTimeoutError(msg string, cause error) *DuplError
- func NewValidationError(msg string, cause error) *DuplError
- type EnumValidationError
- type ErrorType
- type MarshalError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleMarshalingError ¶
HandleMarshalingError provides unified JSON marshaling error handling.
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 ¶
type DuplError struct {
Type ErrorType
Message string
File string
Line int
Cause error
Stack string
}
DuplError is the main error type with rich context.
func NewAnalysisError ¶
NewAnalysisError creates a new analysis error.
func NewCancelledError ¶
NewCancelledError creates a new cancelled error for user-initiated cancellation.
func NewConfigError ¶
NewConfigError creates a new configuration error.
func NewDetectionError ¶
NewDetectionError creates a new detection 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 NewParseError ¶
NewParseError creates a new parse error with context.
func NewTimeoutError ¶
NewTimeoutError creates a new timeout error.
func NewValidationError ¶
NewValidationError creates a new validation error.
type EnumValidationError ¶
EnumValidationError provides domain-specific error context for enum validation failures.
func NewEnumValidationError ¶
func NewEnumValidationError(enumType, enumValue string, cause error) *EnumValidationError
NewEnumValidationError creates a new enum validation error with rich context.
func (*EnumValidationError) Error ¶
func (e *EnumValidationError) Error() string
Error implements the error interface for EnumValidationError.
type ErrorType ¶
type ErrorType string
ErrorType categorizes different types of errors.
const ( ParseError ErrorType = "parse" ConfigError ErrorType = "config" IOError ErrorType = "io" ValidationError ErrorType = "validation" InternalError ErrorType = "internal" DetectionError ErrorType = "detection" AnalysisError ErrorType = "analysis" FileError ErrorType = "file" TimeoutError ErrorType = "timeout" CacheError ErrorType = "cache" CancelledError ErrorType = "cancelled" )
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