errors

package
v0.0.0-...-df4846f Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package errors provides type-safe error handling for dupl

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleMarshalingError

func HandleMarshalingError(operation, context string, err error) error

HandleMarshalingError provides unified JSON marshaling error handling.

func Is

func Is(err error, errorType ErrorType) bool

Is checks if error matches a specific type.

func SafeMarshal

func SafeMarshal(v any, context string) ([]byte, error)

SafeMarshal provides safe marshaling with consistent error handling.

func SafeMarshalIndent

func SafeMarshalIndent(v any, prefix, indent, context string) ([]byte, error)

SafeMarshalIndent provides safe indented marshaling with consistent error handling.

func SafeMarshalIndentNilSafe

func SafeMarshalIndentNilSafe(v any, prefix, indent, nilErrorMessage string) ([]byte, error)

SafeMarshalIndentNilSafe provides safe indented marshaling with nil check. Returns a validation error if the input is nil.

func SafeMarshalNilSafe

func SafeMarshalNilSafe(v any, nilErrorMessage string) ([]byte, error)

SafeMarshalNilSafe provides safe marshaling with nil check. Returns a validation error if the input is nil.

func SafeUnmarshal

func SafeUnmarshal(data []byte, v any, context string) error

SafeUnmarshal provides safe unmarshaling with consistent error handling.

func Wrap

func Wrap(err error, errorType ErrorType, msg string) error

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

func WrapConfig(err error, context string) error

WrapConfig wraps an error as a ConfigError.

func WrapFile

func WrapFile(err error, file, operation string) error

WrapFile wraps an error as a FileError with operation context.

func WrapIO

func WrapIO(err error, file, operation string) error

WrapIO wraps an error as an IOError with file context.

func WrapValidation

func WrapValidation(err error, context string) error

WrapValidation wraps an error as a ValidationError.

func Wrapf

func Wrapf(err error, errorType ErrorType, format string, args ...any) error

Wrapf wraps an error with formatted context using the specified error type.

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

func NewAnalysisError(
	msg string,
	cause error,
) *DuplError

NewAnalysisError creates a new analysis error.

func NewCancelledError

func NewCancelledError(msg string, cause error) *DuplError

NewCancelledError creates a new cancelled error for user-initiated cancellation.

func NewConfigError

func NewConfigError(msg string, cause error) *DuplError

NewConfigError creates a new configuration error.

func NewDetectionError

func NewDetectionError(msg string, cause error) *DuplError

NewDetectionError creates a new detection error.

func NewFileError

func NewFileError(file, msg string, cause error) *DuplError

NewFileError creates a new file error with context.

func NewIOError

func NewIOError(file, msg string, cause error) *DuplError

NewIOError creates a new I/O error.

func NewInternalError

func NewInternalError(
	msg string,
	cause error,
) *DuplError

NewInternalError creates a new internal error.

func NewParseError

func NewParseError(file string, line int, msg string, cause error) *DuplError

NewParseError creates a new parse error with context.

func NewTimeoutError

func NewTimeoutError(
	msg string,
	cause error,
) *DuplError

NewTimeoutError creates a new timeout error.

func NewValidationError

func NewValidationError(msg string, cause error) *DuplError

NewValidationError creates a new validation error.

func (*DuplError) Error

func (e *DuplError) Error() string

Error implements the error interface.

func (*DuplError) Unwrap

func (e *DuplError) Unwrap() error

Unwrap implements the errors.Wrapper interface.

type EnumValidationError

type EnumValidationError struct {
	DuplError

	EnumValue string
	EnumType  string
}

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"
)

func (ErrorType) String

func (et ErrorType) String() string

GetTypeName returns the string name of an ErrorType.

type MarshalError

type MarshalError struct {
	Operation string
	Context   string
	Cause     error
}

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

Jump to

Keyboard shortcuts

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