errors

package
v1.25.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package errors provides enhanced error handling with retry logic and error classification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClassifyHTTPError

func ClassifyHTTPError(statusCode int, message string) error

ClassifyHTTPError classifies HTTP errors based on status code.

func IsRetryableError

func IsRetryableError(err error) bool

IsRetryableError checks if an error is classified as retryable.

func New

func New(errorType ErrorType, message string) error

New creates a new classified error.

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

func WithContext(err error, key, value string) error

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.

func WithRetry

func WithRetry(ctx context.Context, config RetryConfig, operation func() error) error

WithRetry executes a function with retry logic based on error classification.

func Wrapf

func Wrapf(err error, format string, args ...interface{}) error

Wrapf wraps an error with classification and formatting.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL