Documentation
¶
Overview ¶
Package errors provides error types and utilities for the cache package.
Index ¶
- Variables
- func IsCacheClosed(err error) bool
- func IsCacheError(err error) bool
- func IsContextCanceled(err error) bool
- func IsErrorType(err error, errType ErrorType) bool
- func IsKeyNotFound(err error) bool
- func NewCacheError(errType ErrorType, op string, key any, err error) error
- func RecoverFromPanic(op string, key any) bool
- func ResetErrorMetrics()
- func WrapError(op string, key any, err error) error
- type CacheError
- type ErrorMetrics
- type ErrorType
Constants ¶
This section is empty.
Variables ¶
var ( // Cache errors ErrCacheClosed = errors.New("cache is closed") ErrKeyNotFound = errors.New("key not found") ErrInvalidKey = errors.New("invalid key") ErrInvalidValue = errors.New("invalid value") ErrMemoryLimit = errors.New("memory limit exceeded") ErrCapacityLimit = errors.New("capacity limit exceeded") ErrContextCanceled = errors.New("operation canceled by context") // TTL errors ErrInvalidTTL = errors.New("invalid TTL value") ErrTTLTooShort = errors.New("TTL value is too short") ErrTTLTooLong = errors.New("TTL value is too long") // Store errors ErrStoreError = errors.New("store operation failed") ErrStoreConnection = errors.New("store connection failed") ErrStoreTimeout = errors.New("store operation timed out") ErrInvalidSize = errors.New("max size must be greater than 0") ErrInvalidMemoryLimit = errors.New("max memory cannot be negative") // Data errors ErrCompression = errors.New("compression error") ErrDecompression = errors.New("decompression error") ErrSerialization = errors.New("serialization error") ErrDeserialization = errors.New("deserialization error") // Operation errors ErrReplicationError = errors.New("replication error") ErrBatchOperation = errors.New("batch operation failed") ErrInvalidOperation = errors.New("invalid operation") ErrPermissionDenied = errors.New("permission denied") )
Common error types
Functions ¶
func IsCacheClosed ¶
IsCacheClosed checks if the error is a cache closed error
func IsCacheError ¶
IsCacheError checks if an error is a CacheError
func IsContextCanceled ¶
IsContextCanceled checks if the error is a context canceled error
func IsErrorType ¶
IsErrorType checks if an error is of a specific type
func IsKeyNotFound ¶
IsKeyNotFound checks if the error is a key not found error
func NewCacheError ¶
NewCacheError creates a new CacheError
func RecoverFromPanic ¶
RecoverFromPanic recovers from a panic and updates metrics
Types ¶
type CacheError ¶
CacheError represents a cache operation error
func GetCacheError ¶
func GetCacheError(err error) *CacheError
GetCacheError returns the CacheError if the error is a CacheError
func (*CacheError) Is ¶
func (e *CacheError) Is(target error) bool
Is reports whether the target error is of the same type as the receiver
type ErrorMetrics ¶
type ErrorMetrics struct { // Error counts by type CacheErrors atomic.Int64 StoreErrors atomic.Int64 ValidationErrors atomic.Int64 OperationErrors atomic.Int64 // Last error timestamps LastCacheError atomic.Value // time.Time LastStoreError atomic.Value // time.Time LastValidationError atomic.Value // time.Time LastOperationError atomic.Value // time.Time // Error recovery stats PanicRecoveries atomic.Int64 LastPanic atomic.Value // time.Time }
ErrorMetrics tracks error statistics
func GetErrorMetrics ¶
func GetErrorMetrics() *ErrorMetrics
GetErrorMetrics returns the current error metrics
type ErrorType ¶
type ErrorType string
ErrorType represents the category of error
const ( // ErrorTypeCache represents cache-specific errors ErrorTypeCache ErrorType = "cache" // ErrorTypeStore represents storage backend errors ErrorTypeStore ErrorType = "store" // ErrorTypeValidation represents validation errors ErrorTypeValidation ErrorType = "validation" // ErrorTypeOperation represents operation-specific errors ErrorTypeOperation ErrorType = "operation" )