Documentation
¶
Index ¶
- func RetryOperation(ctx context.Context, operation func() error, maxRetries int, ...) error
- func RetryWithExponentialBackoff(ctx context.Context, operation func() error, config BackoffConfig) error
- type BackoffConfig
- type DriftError
- func (e *DriftError) Error() string
- func (e *DriftError) Is(target error) bool
- func (e *DriftError) ToJSON() string
- func (e *DriftError) Unwrap() error
- func (e *DriftError) WithDetails(key string, value interface{}) *DriftError
- func (e *DriftError) WithRecovery(strategy RecoveryStrategy) *DriftError
- func (e *DriftError) WithUserHelp(help string) *DriftError
- type ErrorBuilder
- func (b *ErrorBuilder) Build() *DriftError
- func (b *ErrorBuilder) Error() error
- func (b *ErrorBuilder) WithCode(code string) *ErrorBuilder
- func (b *ErrorBuilder) WithContext(ctx context.Context) *ErrorBuilder
- func (b *ErrorBuilder) WithDetails(key string, value interface{}) *ErrorBuilder
- func (b *ErrorBuilder) WithOperation(operation string) *ErrorBuilder
- func (b *ErrorBuilder) WithProvider(provider string) *ErrorBuilder
- func (b *ErrorBuilder) WithRecovery(strategy RecoveryStrategy) *ErrorBuilder
- func (b *ErrorBuilder) WithResource(resource string) *ErrorBuilder
- func (b *ErrorBuilder) WithRetry(retryable bool, retryAfter time.Duration) *ErrorBuilder
- func (b *ErrorBuilder) WithSeverity(severity ErrorSeverity) *ErrorBuilder
- func (b *ErrorBuilder) WithUserHelp(help string) *ErrorBuilder
- func (b *ErrorBuilder) WithWrapped(err error) *ErrorBuilder
- type ErrorContext
- type ErrorHandler
- type ErrorSeverity
- type ErrorType
- type RecoveryExecutor
- type RecoveryFunc
- type RecoveryMetrics
- type RecoveryStrategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RetryOperation ¶
func RetryOperation(ctx context.Context, operation func() error, maxRetries int, delay time.Duration) error
RetryOperation wraps an operation with retry logic
func RetryWithExponentialBackoff ¶
func RetryWithExponentialBackoff(ctx context.Context, operation func() error, config BackoffConfig) error
RetryWithExponentialBackoff retries with exponential backoff
Types ¶
type BackoffConfig ¶
BackoffConfig configures exponential backoff
func DefaultBackoffConfig ¶
func DefaultBackoffConfig() BackoffConfig
DefaultBackoffConfig returns default backoff configuration
type DriftError ¶
type DriftError struct {
Type ErrorType `json:"type"`
Severity ErrorSeverity `json:"severity"`
Code string `json:"code,omitempty"`
Message string `json:"message"`
UserHelp string `json:"user_help,omitempty"`
Resource string `json:"resource,omitempty"`
Provider string `json:"provider,omitempty"`
Operation string `json:"operation,omitempty"`
Details map[string]interface{} `json:"details,omitempty"`
Timestamp time.Time `json:"timestamp"`
TraceID string `json:"trace_id,omitempty"`
StackTrace string `json:"stack_trace,omitempty"`
Wrapped error `json:"-"`
Retryable bool `json:"retryable"`
RetryAfter time.Duration `json:"retry_after,omitempty"`
Recovery RecoveryStrategy `json:"recovery,omitempty"`
}
DriftError is the enhanced error type with context
func NewNotFoundError ¶
func NewNotFoundError(resource string) *DriftError
NewNotFoundError creates a not found error
func NewTimeoutError ¶
func NewTimeoutError(operation string, duration time.Duration) *DriftError
NewTimeoutError creates a timeout error
func NewTransientError ¶
func NewTransientError(message string, retryAfter time.Duration) *DriftError
NewTransientError creates a transient error that can be retried
func NewValidationError ¶
func NewValidationError(resource string, message string) *DriftError
NewValidationError creates a validation error
func (*DriftError) Is ¶
func (e *DriftError) Is(target error) bool
Is implements errors.Is interface
func (*DriftError) WithDetails ¶
func (e *DriftError) WithDetails(key string, value interface{}) *DriftError
WithDetails adds additional context details
func (*DriftError) WithRecovery ¶
func (e *DriftError) WithRecovery(strategy RecoveryStrategy) *DriftError
WithRecovery adds recovery strategy
func (*DriftError) WithUserHelp ¶
func (e *DriftError) WithUserHelp(help string) *DriftError
WithUserHelp adds user-friendly help text
type ErrorBuilder ¶
type ErrorBuilder struct {
// contains filtered or unexported fields
}
ErrorBuilder provides fluent API for building errors
func NewError ¶
func NewError(errType ErrorType, message string) *ErrorBuilder
NewError creates a new error builder
func (*ErrorBuilder) Build ¶
func (b *ErrorBuilder) Build() *DriftError
Build returns the built error
func (*ErrorBuilder) WithCode ¶
func (b *ErrorBuilder) WithCode(code string) *ErrorBuilder
WithCode sets error code
func (*ErrorBuilder) WithContext ¶
func (b *ErrorBuilder) WithContext(ctx context.Context) *ErrorBuilder
WithContext adds context values to error
func (*ErrorBuilder) WithDetails ¶
func (b *ErrorBuilder) WithDetails(key string, value interface{}) *ErrorBuilder
WithDetails adds context details
func (*ErrorBuilder) WithOperation ¶
func (b *ErrorBuilder) WithOperation(operation string) *ErrorBuilder
WithOperation sets the operation that failed
func (*ErrorBuilder) WithProvider ¶
func (b *ErrorBuilder) WithProvider(provider string) *ErrorBuilder
WithProvider sets the cloud provider
func (*ErrorBuilder) WithRecovery ¶
func (b *ErrorBuilder) WithRecovery(strategy RecoveryStrategy) *ErrorBuilder
WithRecovery adds recovery strategy
func (*ErrorBuilder) WithResource ¶
func (b *ErrorBuilder) WithResource(resource string) *ErrorBuilder
WithResource sets the affected resource
func (*ErrorBuilder) WithRetry ¶
func (b *ErrorBuilder) WithRetry(retryable bool, retryAfter time.Duration) *ErrorBuilder
WithRetry marks error as retryable
func (*ErrorBuilder) WithSeverity ¶
func (b *ErrorBuilder) WithSeverity(severity ErrorSeverity) *ErrorBuilder
WithSeverity sets error severity
func (*ErrorBuilder) WithUserHelp ¶
func (b *ErrorBuilder) WithUserHelp(help string) *ErrorBuilder
WithUserHelp adds user help text
func (*ErrorBuilder) WithWrapped ¶
func (b *ErrorBuilder) WithWrapped(err error) *ErrorBuilder
WithWrapped wraps another error
type ErrorContext ¶
ErrorContext adds error context to context.Context
func WithErrorContext ¶
func WithErrorContext(ctx context.Context) *ErrorContext
WithErrorContext creates a new error context
func (*ErrorContext) AddError ¶
func (ec *ErrorContext) AddError(err error)
AddError adds an error to the context
func (*ErrorContext) GetErrors ¶
func (ec *ErrorContext) GetErrors() []error
GetErrors returns all errors
func (*ErrorContext) GetFirstError ¶
func (ec *ErrorContext) GetFirstError() error
GetFirstError returns the first error or nil
func (*ErrorContext) HasErrors ¶
func (ec *ErrorContext) HasErrors() bool
HasErrors returns true if there are errors
type ErrorHandler ¶
type ErrorHandler struct {
// contains filtered or unexported fields
}
ErrorHandler provides centralized error handling
func NewErrorHandler ¶
func NewErrorHandler() *ErrorHandler
NewErrorHandler creates a new error handler
func (*ErrorHandler) Handle ¶
func (h *ErrorHandler) Handle(err error) error
Handle processes an error
func (*ErrorHandler) RegisterHandler ¶
func (h *ErrorHandler) RegisterHandler(errType ErrorType, handler func(*DriftError) error)
RegisterHandler registers a handler for specific error type
func (*ErrorHandler) SetFallback ¶
func (h *ErrorHandler) SetFallback(handler func(*DriftError) error)
SetFallback sets the fallback handler
type ErrorSeverity ¶
type ErrorSeverity string
ErrorSeverity represents the severity level
const ( SeverityCritical ErrorSeverity = "critical" SeverityHigh ErrorSeverity = "high" SeverityMedium ErrorSeverity = "medium" SeverityLow ErrorSeverity = "low" )
type ErrorType ¶
type ErrorType string
ErrorType represents the category of error
const ( // Error types ErrorTypeTransient ErrorType = "transient" // Temporary errors that can be retried ErrorTypePermanent ErrorType = "permanent" // Errors that won't resolve with retry ErrorTypeUser ErrorType = "user" // User input/configuration errors ErrorTypeSystem ErrorType = "system" // System/infrastructure errors ErrorTypeValidation ErrorType = "validation" // Data validation errors ErrorTypeNotFound ErrorType = "not_found" // Resource not found errors ErrorTypeConflict ErrorType = "conflict" // Resource conflict errors ErrorTypeTimeout ErrorType = "timeout" // Operation timeout errors )
type RecoveryExecutor ¶
type RecoveryExecutor struct {
// contains filtered or unexported fields
}
RecoveryExecutor handles error recovery strategies
func NewRecoveryExecutor ¶
func NewRecoveryExecutor() *RecoveryExecutor
NewRecoveryExecutor creates a new recovery executor
func (*RecoveryExecutor) Execute ¶
func (r *RecoveryExecutor) Execute(ctx context.Context, err *DriftError) error
Execute attempts to recover from an error
func (*RecoveryExecutor) RegisterStrategy ¶
func (r *RecoveryExecutor) RegisterStrategy(name string, fn RecoveryFunc)
RegisterStrategy registers a custom recovery strategy
type RecoveryFunc ¶
type RecoveryFunc func(ctx context.Context, err *DriftError) error
RecoveryFunc is a function that attempts to recover from an error
type RecoveryMetrics ¶
RecoveryMetrics tracks recovery attempts and success rates