package errors import ( "fmt" ) // Error codes const ( ErrHostNotFound = "HOST_NOT_FOUND" ErrAuthFailed = "AUTH_FAILED" ErrConnectionTimeout = "CONNECTION_TIMEOUT" ErrInvalidConfig = "INVALID_CONFIG" ErrKeyNotFound = "KEY_NOT_FOUND" ErrPermissionDenied = "PERMISSION_DENIED" ErrFileCorrupted = "FILE_CORRUPTED" ErrInvalidCredentials = "INVALID_CREDENTIALS" ) // AppError represents an application error with code, message, cause, and hints type AppError struct { Code string Message string Cause error Hints []string } // Error implements the error interface func (e *AppError) Error() string { if e.Cause != nil { return fmt.Sprintf("[%s] %s: %v", e.Code, e.Message, e.Cause) } return fmt.Sprintf("[%s] %s", e.Code, e.Message) } // Unwrap returns the underlying cause for use with errors.Is/errors.As func (e *AppError) Unwrap() error { return e.Cause } // NewAppError creates a new application error func NewAppError(code, message string, cause error, hints []string) *AppError { return &AppError{ Code: code, Message: message, Cause: cause, Hints: hints, } }