Documentation
¶
Index ¶
- type ErrorBuilder
- func (b *ErrorBuilder) Build() *ORMError
- func (b *ErrorBuilder) Code(code string) *ErrorBuilder
- func (b *ErrorBuilder) Context(key string, value interface{}) *ErrorBuilder
- func (b *ErrorBuilder) Details(details string) *ErrorBuilder
- func (b *ErrorBuilder) Field(field string) *ErrorBuilder
- func (b *ErrorBuilder) Operation(operation string) *ErrorBuilder
- func (b *ErrorBuilder) Query(query string, params ...interface{}) *ErrorBuilder
- func (b *ErrorBuilder) Retry(retryable bool, retryCount int, retryDelay time.Duration) *ErrorBuilder
- func (b *ErrorBuilder) Severity(severity ErrorSeverity) *ErrorBuilder
- func (b *ErrorBuilder) Table(table string) *ErrorBuilder
- func (b *ErrorBuilder) Value(value interface{}) *ErrorBuilder
- type ErrorClassifier
- type ErrorHandler
- type ErrorSeverity
- type ErrorType
- type ORMError
- func New(errorType ErrorType, message string) *ORMError
- func NewConnectionError(message string) *ORMError
- func NewConstraintError(message string) *ORMError
- func NewDuplicateError(message string) *ORMError
- func NewNotFoundError(message string) *ORMError
- func NewQueryError(message string) *ORMError
- func NewSecurityError(message string) *ORMError
- func NewTimeoutError(message string) *ORMError
- func NewTransactionError(message string) *ORMError
- func NewValidationError(message string) *ORMError
- func Wrap(err error, errorType ErrorType, message string) *ORMError
- func (e *ORMError) AddContext(key string, value interface{})
- func (e *ORMError) Error() string
- func (e *ORMError) GetContext() map[string]interface{}
- func (e *ORMError) GetSeverity() ErrorSeverity
- func (e *ORMError) GetType() ErrorType
- func (e *ORMError) IsRetryable() bool
- func (e *ORMError) Unwrap() error
- func (e *ORMError) WithCode(code string) *ORMError
- func (e *ORMError) WithDetails(details string) *ORMError
- func (e *ORMError) WithField(field string) *ORMError
- func (e *ORMError) WithOperation(operation string) *ORMError
- func (e *ORMError) WithQuery(query string, params ...interface{}) *ORMError
- func (e *ORMError) WithRetry(retryable bool, retryCount int, retryDelay time.Duration) *ORMError
- func (e *ORMError) WithSeverity(severity ErrorSeverity) *ORMError
- func (e *ORMError) WithTable(table string) *ORMError
- func (e *ORMError) WithValue(value interface{}) *ORMError
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) 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 NewConnectionError ¶
Common error constructors
func NewConstraintError ¶
func NewDuplicateError ¶
func NewNotFoundError ¶
func NewQueryError ¶
func NewSecurityError ¶
func NewTimeoutError ¶
func NewTransactionError ¶
func NewValidationError ¶
func (*ORMError) AddContext ¶
AddContext adds context information to the error
func (*ORMError) GetContext ¶
GetContext returns the error context
func (*ORMError) GetSeverity ¶
func (e *ORMError) GetSeverity() ErrorSeverity
GetSeverity returns the error severity
func (*ORMError) IsRetryable ¶
IsRetryable returns true if the error is retryable
func (*ORMError) WithDetails ¶
WithDetails sets the error details
func (*ORMError) WithOperation ¶
WithOperation sets the operation that caused the error
func (*ORMError) WithSeverity ¶
func (e *ORMError) WithSeverity(severity ErrorSeverity) *ORMError
WithSeverity sets the error severity