Documentation
¶
Overview ¶
Package errors provides enhanced error handling with retry logic and error classification.
Index ¶
- func ClassifyHTTPError(statusCode int, message string) error
- func IsRetryableError(err error) bool
- func New(errorType ErrorType, message string) error
- func RetryWithBackoff(ctx context.Context, operation func() error, opts ...func(*RetryConfig)) error
- func WithBaseDelay(delay time.Duration) func(*RetryConfig)
- func WithContext(err error, key, value string) error
- func WithMaxAttempts(attempts int) func(*RetryConfig)
- func WithMaxDelay(delay time.Duration) func(*RetryConfig)
- func WithRetry(ctx context.Context, config RetryConfig, operation func() error) error
- func Wrapf(err error, format string, args ...interface{}) error
- type ClassifiedError
- type ErrorType
- type RetryConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClassifyHTTPError ¶
ClassifyHTTPError classifies HTTP errors based on status code.
func IsRetryableError ¶
IsRetryableError checks if an error is classified as retryable.
func RetryWithBackoff ¶
func RetryWithBackoff(ctx context.Context, operation func() error, opts ...func(*RetryConfig)) error
RetryWithBackoff executes a function with exponential backoff retry.
func WithBaseDelay ¶
func WithBaseDelay(delay time.Duration) func(*RetryConfig)
WithBaseDelay sets the base delay for retries.
func WithContext ¶
WithContext adds context information to an error.
func WithMaxAttempts ¶
func WithMaxAttempts(attempts int) func(*RetryConfig)
WithMaxAttempts sets the maximum number of retry attempts.
func WithMaxDelay ¶
func WithMaxDelay(delay time.Duration) func(*RetryConfig)
WithMaxDelay sets the maximum delay between retries.
Types ¶
type ClassifiedError ¶
type ClassifiedError struct {
Type ErrorType
Retryable bool
Context map[string]string
// contains filtered or unexported fields
}
ClassifiedError wraps an error with classification information.
func ClassifyError ¶
func ClassifyError(err error) *ClassifiedError
ClassifyError analyzes an error and returns a classified version.
func (*ClassifiedError) Error ¶
func (e *ClassifiedError) Error() string
Error returns the error message with classification info.
func (*ClassifiedError) Unwrap ¶
func (e *ClassifiedError) Unwrap() error
Unwrap returns the underlying error.
type ErrorType ¶
type ErrorType string
ErrorType classifies errors for better handling and metrics.
const ( // ErrorTypeNetwork represents network-related errors (retryable) ErrorTypeNetwork ErrorType = "network" // ErrorTypeTimeout represents timeout-related errors (retryable) ErrorTypeTimeout ErrorType = "timeout" // ErrorTypeConnection represents connection-related errors (retryable) ErrorTypeConnection ErrorType = "connection" // ErrorTypeRateLimit represents rate limit errors from registries (retryable) ErrorTypeRateLimit ErrorType = "rate_limit" // ErrorTypeAuth represents authentication errors (not retryable) ErrorTypeAuth ErrorType = "authentication" // ErrorTypePermission represents permission errors (not retryable) ErrorTypePermission ErrorType = "permission" // ErrorTypeNotFound represents resource not found errors (not retryable) ErrorTypeNotFound ErrorType = "not_found" // ErrorTypeBuild represents build-related errors (usually not retryable) ErrorTypeBuild ErrorType = "build" // ErrorTypeConfig represents configuration errors (not retryable) ErrorTypeConfig ErrorType = "configuration" // ErrorTypeValidation represents validation errors (not retryable) ErrorTypeValidation ErrorType = "validation" // ErrorTypeResource represents resource-related system errors (retryable) ErrorTypeResource ErrorType = "resource" // ErrorTypeIO represents I/O-related errors (some may be retryable) ErrorTypeIO ErrorType = "io" // ErrorTypeUnknown represents unknown error types ErrorTypeUnknown ErrorType = "unknown" )
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts int
BaseDelay time.Duration
MaxDelay time.Duration
JitterFactor float64
BackoffFactor float64
}
RetryConfig configuration for retry operations.
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns a sensible default retry configuration.