errors

package
v0.0.0-...-c659449 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 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 SafeUnmarshal

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

SafeUnmarshal provides safe unmarshaling with consistent error handling.

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 NewConfigError

func NewConfigError(msg string, cause error) *DuplError

NewConfigError creates a new configuration error.

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

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