errors

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorBuilder

type ErrorBuilder struct {
	// contains filtered or unexported fields
}

ErrorBuilder provides a fluent interface for building errors

func NewBuilder

func NewBuilder(errorType ErrorType, message string) *ErrorBuilder

NewBuilder creates a new error builder

func (*ErrorBuilder) Build

func (b *ErrorBuilder) Build() *ORMError

Build returns the built error

func (*ErrorBuilder) Code

func (b *ErrorBuilder) Code(code string) *ErrorBuilder

Code sets the error code

func (*ErrorBuilder) Context

func (b *ErrorBuilder) Context(key string, value interface{}) *ErrorBuilder

Context adds context information

func (*ErrorBuilder) Details

func (b *ErrorBuilder) Details(details string) *ErrorBuilder

Details sets the error details

func (*ErrorBuilder) Field

func (b *ErrorBuilder) Field(field string) *ErrorBuilder

Field sets the field

func (*ErrorBuilder) Operation

func (b *ErrorBuilder) Operation(operation string) *ErrorBuilder

Operation sets the operation

func (*ErrorBuilder) Query

func (b *ErrorBuilder) Query(query string, params ...interface{}) *ErrorBuilder

Query sets the query

func (*ErrorBuilder) Retry

func (b *ErrorBuilder) Retry(retryable bool, retryCount int, retryDelay time.Duration) *ErrorBuilder

Retry sets retry information

func (*ErrorBuilder) Severity

func (b *ErrorBuilder) Severity(severity ErrorSeverity) *ErrorBuilder

Severity sets the error severity

func (*ErrorBuilder) Table

func (b *ErrorBuilder) Table(table string) *ErrorBuilder

Table sets the table

func (*ErrorBuilder) Value

func (b *ErrorBuilder) Value(value interface{}) *ErrorBuilder

Value sets the value

type ErrorClassifier

type ErrorClassifier struct {
	// contains filtered or unexported fields
}

ErrorClassifier classifies errors based on their type and content

func NewErrorClassifier

func NewErrorClassifier() *ErrorClassifier

NewErrorClassifier creates a new error classifier

func (*ErrorClassifier) ClassifyError

func (ec *ErrorClassifier) ClassifyError(err error, operation string) *ORMError

ClassifyError classifies an error and returns an ORMError

type ErrorHandler

type ErrorHandler struct {
	// contains filtered or unexported fields
}

ErrorHandler handles errors with retry logic and logging

func NewErrorHandler

func NewErrorHandler(maxRetries int, retryDelay time.Duration) *ErrorHandler

NewErrorHandler creates a new error handler

func (*ErrorHandler) HandleError

func (eh *ErrorHandler) HandleError(err error, operation string) *ORMError

HandleError handles an error with retry logic

func (*ErrorHandler) RetryWithContext

func (eh *ErrorHandler) RetryWithContext(ctx context.Context, operation func() error, operationName string) error

RetryWithContext retries an operation with context

type ErrorSeverity

type ErrorSeverity string

ErrorSeverity represents the severity level of an error

const (
	ErrorSeverityLow      ErrorSeverity = "1_low"
	ErrorSeverityMedium   ErrorSeverity = "2_medium"
	ErrorSeverityHigh     ErrorSeverity = "3_high"
	ErrorSeverityCritical ErrorSeverity = "4_critical"
)

type ErrorType

type ErrorType string

ErrorType represents the type of error

const (
	// Database errors
	ErrorTypeConnection  ErrorType = "connection"
	ErrorTypeQuery       ErrorType = "query"
	ErrorTypeTransaction ErrorType = "transaction"
	ErrorTypeTimeout     ErrorType = "timeout"
	ErrorTypeDeadlock    ErrorType = "deadlock"
	ErrorTypeConstraint  ErrorType = "constraint"
	ErrorTypeNotFound    ErrorType = "not_found"
	ErrorTypeDuplicate   ErrorType = "duplicate"
	ErrorTypeValidation  ErrorType = "validation"
	ErrorTypeMigration   ErrorType = "migration"
	ErrorTypeReplication ErrorType = "replication"

	// ORM specific errors
	ErrorTypeModel        ErrorType = "model"
	ErrorTypeRelationship ErrorType = "relationship"
	ErrorTypeAssociation  ErrorType = "association"
	ErrorTypeHook         ErrorType = "hook"
	ErrorTypeCallback     ErrorType = "callback"

	// Configuration errors
	ErrorTypeConfig         ErrorType = "config"
	ErrorTypeInitialization ErrorType = "initialization"

	// Cache errors
	ErrorTypeCache        ErrorType = "cache"
	ErrorTypeCacheMiss    ErrorType = "cache_miss"
	ErrorTypeCacheInvalid ErrorType = "cache_invalid"

	// Security errors
	ErrorTypeSecurity     ErrorType = "security"
	ErrorTypeSQLInjection ErrorType = "sql_injection"
	ErrorTypeAccessDenied ErrorType = "access_denied"

	// System errors
	ErrorTypeSystem   ErrorType = "system"
	ErrorTypeResource ErrorType = "resource"
	ErrorTypeNetwork  ErrorType = "network"
	ErrorTypeUnknown  ErrorType = "unknown"
)

type ORMError

type ORMError struct {
	Type       ErrorType              `json:"type"`
	Severity   ErrorSeverity          `json:"severity"`
	Message    string                 `json:"message"`
	Code       string                 `json:"code,omitempty"`
	Details    string                 `json:"details,omitempty"`
	Operation  string                 `json:"operation,omitempty"`
	Table      string                 `json:"table,omitempty"`
	Field      string                 `json:"field,omitempty"`
	Value      interface{}            `json:"value,omitempty"`
	Query      string                 `json:"query,omitempty"`
	Params     []interface{}          `json:"params,omitempty"`
	Retryable  bool                   `json:"retryable"`
	RetryCount int                    `json:"retry_count,omitempty"`
	RetryDelay time.Duration          `json:"retry_delay,omitempty"`
	Context    map[string]interface{} `json:"context,omitempty"`
	Timestamp  time.Time              `json:"timestamp"`
	Stack      string                 `json:"stack,omitempty"`
	Cause      error                  `json:"-"`
}

ORMError represents a comprehensive ORM error

func New

func New(errorType ErrorType, message string) *ORMError

New creates a new ORM error

func NewConnectionError

func NewConnectionError(message string) *ORMError

Common error constructors

func NewConstraintError

func NewConstraintError(message string) *ORMError

func NewDuplicateError

func NewDuplicateError(message string) *ORMError

func NewNotFoundError

func NewNotFoundError(message string) *ORMError

func NewQueryError

func NewQueryError(message string) *ORMError

func NewSecurityError

func NewSecurityError(message string) *ORMError

func NewTimeoutError

func NewTimeoutError(message string) *ORMError

func NewTransactionError

func NewTransactionError(message string) *ORMError

func NewValidationError

func NewValidationError(message string) *ORMError

func Wrap

func Wrap(err error, errorType ErrorType, message string) *ORMError

Wrap wraps an existing error with ORM error information

func (*ORMError) AddContext

func (e *ORMError) AddContext(key string, value interface{})

AddContext adds context information to the error

func (*ORMError) Error

func (e *ORMError) Error() string

Error implements the error interface

func (*ORMError) GetContext

func (e *ORMError) GetContext() map[string]interface{}

GetContext returns the error context

func (*ORMError) GetSeverity

func (e *ORMError) GetSeverity() ErrorSeverity

GetSeverity returns the error severity

func (*ORMError) GetType

func (e *ORMError) GetType() ErrorType

GetType returns the error type

func (*ORMError) IsRetryable

func (e *ORMError) IsRetryable() bool

IsRetryable returns true if the error is retryable

func (*ORMError) Unwrap

func (e *ORMError) Unwrap() error

Unwrap returns the underlying cause error

func (*ORMError) WithCode

func (e *ORMError) WithCode(code string) *ORMError

WithCode sets the error code

func (*ORMError) WithDetails

func (e *ORMError) WithDetails(details string) *ORMError

WithDetails sets the error details

func (*ORMError) WithField

func (e *ORMError) WithField(field string) *ORMError

WithField sets the field involved in the error

func (*ORMError) WithOperation

func (e *ORMError) WithOperation(operation string) *ORMError

WithOperation sets the operation that caused the error

func (*ORMError) WithQuery

func (e *ORMError) WithQuery(query string, params ...interface{}) *ORMError

WithQuery sets the query that caused the error

func (*ORMError) WithRetry

func (e *ORMError) WithRetry(retryable bool, retryCount int, retryDelay time.Duration) *ORMError

WithRetry sets retry information

func (*ORMError) WithSeverity

func (e *ORMError) WithSeverity(severity ErrorSeverity) *ORMError

WithSeverity sets the error severity

func (*ORMError) WithTable

func (e *ORMError) WithTable(table string) *ORMError

WithTable sets the table involved in the error

func (*ORMError) WithValue

func (e *ORMError) WithValue(value interface{}) *ORMError

WithValue sets the value involved in the error

Jump to

Keyboard shortcuts

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