package errors import ( stderrors "errors" "fmt" ) // Is reports whether any error in err's chain matches target. var Is = stderrors.Is // As finds the first error in err's chain that matches target, and if so, sets // target to that error value and returns true. var As = stderrors.As // Unwrap returns the result of calling the Unwrap method on err, if err's // type contains an Unwrap method returning error. // Otherwise, Unwrap returns nil. var Unwrap = stderrors.Unwrap // Standard errors that can be used across packages var ( ErrNotFound = stderrors.New("resource not found") ErrInvalidInput = stderrors.New("invalid input") ErrUnauthorized = stderrors.New("unauthorized") ErrInternalServer = stderrors.New("internal server error") ErrDatabaseOperation = stderrors.New("database operation failed") ) // DatabaseError represents a database-related error type DatabaseError struct { Operation string Err error } func (e *DatabaseError) Error() string { return fmt.Sprintf("database error during %s: %v", e.Operation, e.Err) } func (e *DatabaseError) Unwrap() error { return e.Err } // NewDatabaseError creates a new DatabaseError func NewDatabaseError(operation string, err error) *DatabaseError { return &DatabaseError{ Operation: operation, Err: err, } } // AuthError represents an authentication-related error type AuthError struct { Action string Err error } func (e *AuthError) Error() string { return fmt.Sprintf("authentication error during %s: %v", e.Action, e.Err) } func (e *AuthError) Unwrap() error { return e.Err } // NewAuthError creates a new AuthError func NewAuthError(action string, err error) *AuthError { return &AuthError{ Action: action, Err: err, } } // StorageError represents a storage-related error type StorageError struct { Operation string Bucket string Err error } func (e *StorageError) Error() string { return fmt.Sprintf("storage error during %s on bucket %s: %v", e.Operation, e.Bucket, e.Err) } func (e *StorageError) Unwrap() error { return e.Err } // NewStorageError creates a new StorageError func NewStorageError(operation, bucket string, err error) *StorageError { return &StorageError{ Operation: operation, Bucket: bucket, Err: err, } } // ConfigError represents a configuration-related error type ConfigError struct { Section string Err error } func (e *ConfigError) Error() string { return fmt.Sprintf("configuration error in %s: %v", e.Section, e.Err) } func (e *ConfigError) Unwrap() error { return e.Err } // NewConfigError creates a new ConfigError func NewConfigError(section string, err error) *ConfigError { return &ConfigError{ Section: section, Err: err, } }