Documentation
¶
Overview ¶
Package errors provides error handling functionality for bundle operations
Package errors provides error handling functionality for bundle operations ¶
Package errors provides error handling functionality for bundle operations ¶
Package errors provides error handling functionality for bundle operations ¶
Package errors provides error handling functionality for bundle operations ¶
Package errors provides error handling functionality for bundle operations
Index ¶
- func GetErrorDetails(err error) map[string]interface{}
- func IsRetryableError(err error) bool
- func IsTemporaryError(err error) bool
- func WrapError(err error, message string) error
- func WrapWithContext(err error, ctx context.Context, operation string) error
- func WriteReportJSON(w io.Writer, report *ErrorReport) error
- func WriteReportText(w io.Writer, report *ErrorReport) error
- type AuditLogger
- func (l *AuditLogger) LogBackupCreated(bundleID, targetDir, backupPath string)
- func (l *AuditLogger) LogConflict(bundleID string, conflict interface{}, strategy interface{})
- func (l *AuditLogger) LogEvent(event, component, id string, details map[string]interface{})
- func (l *AuditLogger) LogEventWithStatus(event, component, id, status string, details map[string]interface{})
- func (l *AuditLogger) LogFileInstallation(bundleID, filePath string, success bool, details map[string]interface{})
- func (l *AuditLogger) LogImportComplete(bundleID string, success bool, details map[string]interface{})
- func (l *AuditLogger) LogImportStart(bundleID, bundlePath string, options map[string]interface{})
- func (l *AuditLogger) LogImportSummary(bundleID string, stats map[string]interface{})
- func (l *AuditLogger) LogValidation(bundleID, bundlePath string, level string, success bool, ...)
- type BackupRecoveryStrategy
- type BundleError
- func (e *BundleError) Error() string
- func (e *BundleError) ToJSON() ([]byte, error)
- func (e *BundleError) Unwrap() error
- func (e *BundleError) WithCause(cause error) *BundleError
- func (e *BundleError) WithContext(context map[string]interface{}) *BundleError
- func (e *BundleError) WithDetails(details map[string]interface{}) *BundleError
- func (e *BundleError) WithRetryInfo(attempt, maxRetries int) *BundleError
- type CircuitBreaker
- type ConflictRecoveryStrategy
- type DefaultErrorCategorizer
- type DefaultErrorHandler
- type DefaultErrorReporter
- func (r *DefaultErrorReporter) GenerateErrorReport(ctx context.Context, errors []*BundleError, outputPath string) error
- func (r *DefaultErrorReporter) GenerateReport(ctx context.Context, errors []*BundleError) (*ErrorReport, error)
- func (r *DefaultErrorReporter) Report(ctx context.Context, err *BundleError) error
- type EnhancedErrorHandler
- type ErrorCategorizer
- type ErrorCategory
- type ErrorCode
- type ErrorHandler
- type ErrorLogger
- type ErrorMetrics
- type ErrorRecoverability
- type ErrorReport
- type ErrorReporter
- type ErrorSeverity
- type ErrorStats
- type FileSystemRecoveryStrategy
- type NetworkRecoveryStrategy
- type RecoveryManager
- type RecoveryStrategy
- type RetryPolicy
- type TokenBucketRateLimiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetErrorDetails ¶
GetErrorDetails returns detailed information about an error
func IsRetryableError ¶
IsRetryableError determines if an error is retryable
func IsTemporaryError ¶ added in v0.8.0
IsTemporaryError checks if an error is temporary
func WrapWithContext ¶ added in v0.8.0
WrapWithContext wraps an error with context information
func WriteReportJSON ¶ added in v0.8.0
func WriteReportJSON(w io.Writer, report *ErrorReport) error
WriteReportJSON writes an error report as JSON
func WriteReportText ¶ added in v0.8.0
func WriteReportText(w io.Writer, report *ErrorReport) error
WriteReportText writes an error report as text
Types ¶
type AuditLogger ¶
type AuditLogger struct {
// Writer is the writer for audit logs
Writer io.Writer
// User is the user performing the operation
User string
}
AuditLogger implements the ErrorLogger interface for audit logging
func NewAuditLogger ¶
func NewAuditLogger(writer io.Writer, user string) *AuditLogger
NewAuditLogger creates a new audit logger
func (*AuditLogger) LogBackupCreated ¶
func (l *AuditLogger) LogBackupCreated(bundleID, targetDir, backupPath string)
LogBackupCreated logs a backup creation event
func (*AuditLogger) LogConflict ¶
func (l *AuditLogger) LogConflict(bundleID string, conflict interface{}, strategy interface{})
LogConflict logs a conflict resolution event
func (*AuditLogger) LogEvent ¶
func (l *AuditLogger) LogEvent(event, component, id string, details map[string]interface{})
LogEvent logs an event
func (*AuditLogger) LogEventWithStatus ¶
func (l *AuditLogger) LogEventWithStatus(event, component, id, status string, details map[string]interface{})
LogEventWithStatus logs an event with a status
func (*AuditLogger) LogFileInstallation ¶
func (l *AuditLogger) LogFileInstallation(bundleID, filePath string, success bool, details map[string]interface{})
LogFileInstallation logs a file installation event
func (*AuditLogger) LogImportComplete ¶
func (l *AuditLogger) LogImportComplete(bundleID string, success bool, details map[string]interface{})
LogImportComplete logs the completion of an import operation
func (*AuditLogger) LogImportStart ¶
func (l *AuditLogger) LogImportStart(bundleID, bundlePath string, options map[string]interface{})
LogImportStart logs the start of an import operation
func (*AuditLogger) LogImportSummary ¶
func (l *AuditLogger) LogImportSummary(bundleID string, stats map[string]interface{})
LogImportSummary logs a summary of the import operation
func (*AuditLogger) LogValidation ¶
func (l *AuditLogger) LogValidation(bundleID, bundlePath string, level string, success bool, details map[string]interface{})
LogValidation logs a validation event
type BackupRecoveryStrategy ¶
type BackupRecoveryStrategy struct {
// Logger is the logger for recovery events
Logger io.Writer
// BackupDir is the directory for backups
BackupDir string
}
BackupRecoveryStrategy implements recovery strategies for backup errors
func NewBackupRecoveryStrategy ¶
func NewBackupRecoveryStrategy(logger io.Writer, backupDir string) *BackupRecoveryStrategy
NewBackupRecoveryStrategy creates a new backup recovery strategy
func (*BackupRecoveryStrategy) CanRecover ¶
func (s *BackupRecoveryStrategy) CanRecover(err *BundleError) bool
CanRecover determines if the strategy can recover from an error
func (*BackupRecoveryStrategy) Recover ¶
func (s *BackupRecoveryStrategy) Recover(ctx context.Context, err *BundleError) (bool, error)
Recover attempts to recover from a backup error
type BundleError ¶
type BundleError struct {
// ErrorID is a unique identifier for this error instance
ErrorID string `json:"error_id"`
// Code is the error code
Code ErrorCode `json:"code"`
// Category is the error category
Category ErrorCategory `json:"category"`
// Severity is the error severity
Severity ErrorSeverity `json:"severity"`
// Recoverability indicates if the error is recoverable
Recoverability ErrorRecoverability `json:"recoverability"`
// Message is the human-readable error message
Message string `json:"message"`
// Details contains additional error details
Details map[string]interface{} `json:"details,omitempty"`
// Context contains contextual information
Context map[string]interface{} `json:"context,omitempty"`
// Timestamp is when the error occurred
Timestamp time.Time `json:"timestamp"`
// StackTrace contains the stack trace
StackTrace string `json:"stack_trace,omitempty"`
// RetryAttempt is the current retry attempt
RetryAttempt int `json:"retry_attempt"`
// MaxRetries is the maximum number of retries
MaxRetries int `json:"max_retries"`
// Cause is the underlying error
Cause error `json:"-"`
}
BundleError represents a structured error with additional context
func NewBundleError ¶
func NewBundleError(code ErrorCode, category ErrorCategory, severity ErrorSeverity, recoverability ErrorRecoverability, message string) *BundleError
NewBundleError creates a new BundleError
func (*BundleError) Error ¶
func (e *BundleError) Error() string
Error implements the error interface
func (*BundleError) ToJSON ¶ added in v0.8.0
func (e *BundleError) ToJSON() ([]byte, error)
ToJSON converts the error to JSON
func (*BundleError) Unwrap ¶ added in v0.8.0
func (e *BundleError) Unwrap() error
Unwrap returns the underlying error
func (*BundleError) WithCause ¶ added in v0.8.0
func (e *BundleError) WithCause(cause error) *BundleError
WithCause sets the underlying cause
func (*BundleError) WithContext ¶
func (e *BundleError) WithContext(context map[string]interface{}) *BundleError
WithContext adds context to the error
func (*BundleError) WithDetails ¶ added in v0.8.0
func (e *BundleError) WithDetails(details map[string]interface{}) *BundleError
WithDetails adds details to the error
func (*BundleError) WithRetryInfo ¶ added in v0.8.0
func (e *BundleError) WithRetryInfo(attempt, maxRetries int) *BundleError
WithRetryInfo sets retry information
type CircuitBreaker ¶ added in v0.8.0
type CircuitBreaker struct {
// State is the current state
State string
// FailureCount tracks failures
FailureCount int
// SuccessCount tracks successes
SuccessCount int
// LastFailureTime is the time of last failure
LastFailureTime time.Time
// Threshold is the failure threshold
Threshold int
// Timeout is the timeout duration
Timeout time.Duration
// contains filtered or unexported fields
}
CircuitBreaker implements circuit breaker pattern
func NewCircuitBreaker ¶ added in v0.8.0
func NewCircuitBreaker(threshold int, timeout time.Duration) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker
func (*CircuitBreaker) CanProceed ¶ added in v0.8.0
func (cb *CircuitBreaker) CanProceed() bool
CanProceed checks if the circuit breaker allows proceeding
func (*CircuitBreaker) RecordFailure ¶ added in v0.8.0
func (cb *CircuitBreaker) RecordFailure()
RecordFailure records a failed operation
func (*CircuitBreaker) RecordSuccess ¶ added in v0.8.0
func (cb *CircuitBreaker) RecordSuccess()
RecordSuccess records a successful operation
type ConflictRecoveryStrategy ¶
type ConflictRecoveryStrategy struct {
// Logger is the logger for recovery events
Logger io.Writer
// Force indicates whether to force resolution
Force bool
}
ConflictRecoveryStrategy implements recovery strategies for conflict errors
func NewConflictRecoveryStrategy ¶
func NewConflictRecoveryStrategy(logger io.Writer, force bool) *ConflictRecoveryStrategy
NewConflictRecoveryStrategy creates a new conflict recovery strategy
func (*ConflictRecoveryStrategy) CanRecover ¶
func (s *ConflictRecoveryStrategy) CanRecover(err *BundleError) bool
CanRecover determines if the strategy can recover from an error
func (*ConflictRecoveryStrategy) Recover ¶
func (s *ConflictRecoveryStrategy) Recover(ctx context.Context, err *BundleError) (bool, error)
Recover attempts to recover from a conflict error
type DefaultErrorCategorizer ¶
type DefaultErrorCategorizer struct {
// Logger is the logger for categorization events
Logger io.Writer
}
DefaultErrorCategorizer is the default implementation of ErrorCategorizer
func (*DefaultErrorCategorizer) CategorizeError ¶
func (c *DefaultErrorCategorizer) CategorizeError(err error) (ErrorCategory, ErrorSeverity, ErrorRecoverability)
CategorizeError categorizes an error based on its type and message
type DefaultErrorHandler ¶
type DefaultErrorHandler struct {
// Logger is the logger for error events
Logger interface{}
// Metrics is the metrics collector
Metrics interface{}
// RecoveryStrategy is the strategy for recovering from errors
RecoveryStrategy RecoveryStrategy
}
DefaultErrorHandler is the default error handler implementation
func NewDefaultErrorHandler ¶ added in v0.8.0
func NewDefaultErrorHandler() *DefaultErrorHandler
NewDefaultErrorHandler creates a new default error handler
func (*DefaultErrorHandler) HandleError ¶
func (h *DefaultErrorHandler) HandleError(ctx context.Context, err error) error
HandleError handles an error
func (*DefaultErrorHandler) SetRecoveryStrategy ¶ added in v0.8.0
func (h *DefaultErrorHandler) SetRecoveryStrategy(strategy RecoveryStrategy)
SetRecoveryStrategy sets the recovery strategy
type DefaultErrorReporter ¶
type DefaultErrorReporter struct {
Writer io.Writer
AuditLogger *AuditLogger
}
DefaultErrorReporter is the default implementation of ErrorReporter
func NewErrorReporter ¶
func NewErrorReporter(writer io.Writer, auditLogger *AuditLogger) *DefaultErrorReporter
NewErrorReporter creates a new error reporter
func (*DefaultErrorReporter) GenerateErrorReport ¶
func (r *DefaultErrorReporter) GenerateErrorReport(ctx context.Context, errors []*BundleError, outputPath string) error
GenerateErrorReport generates and writes an error report to a file
func (*DefaultErrorReporter) GenerateReport ¶ added in v0.8.0
func (r *DefaultErrorReporter) GenerateReport(ctx context.Context, errors []*BundleError) (*ErrorReport, error)
GenerateReport generates a comprehensive error report
func (*DefaultErrorReporter) Report ¶ added in v0.8.0
func (r *DefaultErrorReporter) Report(ctx context.Context, err *BundleError) error
Report reports a single error
type EnhancedErrorHandler ¶
type EnhancedErrorHandler struct {
// ErrorCategorizer categorizes errors
ErrorCategorizer ErrorCategorizer
// RecoveryManager manages recovery strategies
RecoveryManager *RecoveryManager
// CircuitBreaker provides circuit breaking functionality
CircuitBreaker *CircuitBreaker
// RetryPolicy defines retry behavior
RetryPolicy *RetryPolicy
// RateLimiter limits error handling rate
RateLimiter *TokenBucketRateLimiter
// Metrics tracks error metrics
Metrics map[string]int
// ErrorMetrics tracks detailed error metrics
ErrorMetrics *ErrorMetrics
// contains filtered or unexported fields
}
EnhancedErrorHandler provides enhanced error handling capabilities
func NewEnhancedErrorHandler ¶
func NewEnhancedErrorHandler() *EnhancedErrorHandler
NewEnhancedErrorHandler creates a new enhanced error handler
func (*EnhancedErrorHandler) GetErrorMetrics ¶
func (h *EnhancedErrorHandler) GetErrorMetrics() *ErrorMetrics
GetErrorMetrics returns detailed error metrics
func (*EnhancedErrorHandler) GetMetrics ¶ added in v0.8.0
func (h *EnhancedErrorHandler) GetMetrics() map[string]int
GetMetrics returns error handling metrics
func (*EnhancedErrorHandler) HandleError ¶
func (h *EnhancedErrorHandler) HandleError(ctx context.Context, err error) error
HandleError handles an error with enhanced capabilities
func (*EnhancedErrorHandler) RetryWithPolicy ¶ added in v0.8.0
func (h *EnhancedErrorHandler) RetryWithPolicy(ctx context.Context, err error) error
RetryWithPolicy retries an operation with the configured policy
type ErrorCategorizer ¶
type ErrorCategorizer interface {
// CategorizeError categorizes an error
CategorizeError(err error) (ErrorCategory, ErrorSeverity, ErrorRecoverability)
}
ErrorCategorizer defines the interface for error categorization
func NewErrorCategorizer ¶
func NewErrorCategorizer(logger io.Writer) ErrorCategorizer
NewErrorCategorizer creates a new error categorizer
type ErrorCategory ¶
type ErrorCategory string
ErrorCategory represents the category of an error
const ( ValidationError ErrorCategory = "validation" FileSystemError ErrorCategory = "filesystem" NetworkError ErrorCategory = "network" ConfigurationError ErrorCategory = "configuration" SecurityError ErrorCategory = "security" PermissionError ErrorCategory = "permission" BackupError ErrorCategory = "backup" ConflictError ErrorCategory = "conflict" UnknownError ErrorCategory = "unknown" )
Error categories
func GetErrorCategory ¶
func GetErrorCategory(err error) ErrorCategory
GetErrorCategory returns the category of an error
type ErrorCode ¶ added in v0.8.0
type ErrorCode string
ErrorCode represents a type of error
const ( // Import errors ImportErrorCode ErrorCode = "IMPORT_ERROR" ValidationErrorCode ErrorCode = "VALIDATION_ERROR" ConversionErrorCode ErrorCode = "CONVERSION_ERROR" FileSystemErrorCode ErrorCode = "FILE_SYSTEM_ERROR" NetworkErrorCode ErrorCode = "NETWORK_ERROR" ConfigurationErrorCode ErrorCode = "CONFIGURATION_ERROR" SecurityErrorCode ErrorCode = "SECURITY_ERROR" PermissionErrorCode ErrorCode = "PERMISSION_ERROR" BackupErrorCode ErrorCode = "BACKUP_ERROR" ConflictErrorCode ErrorCode = "CONFLICT_ERROR" UnknownErrorCode ErrorCode = "UNKNOWN_ERROR" )
Error codes
type ErrorHandler ¶
ErrorHandler defines the interface for error handling
type ErrorLogger ¶
type ErrorLogger interface {
// LogEvent logs an event
LogEvent(event, component, id string, details map[string]interface{})
// LogEventWithStatus logs an event with a status
LogEventWithStatus(event, component, id, status string, details map[string]interface{})
}
ErrorLogger defines the interface for logging errors
type ErrorMetrics ¶
type ErrorMetrics struct {
TotalErrors int `json:"total_errors"`
RecoveredErrors int `json:"recovered_errors"`
UnrecoveredErrors int `json:"unrecovered_errors"`
RetryAttempts int `json:"retry_attempts"`
}
ErrorMetrics contains error handling metrics
type ErrorRecoverability ¶
type ErrorRecoverability string
ErrorRecoverability represents whether an error is recoverable
const ( RecoverableError ErrorRecoverability = "recoverable" NonRecoverableError ErrorRecoverability = "non_recoverable" )
Error recoverability types
type ErrorReport ¶
type ErrorReport struct {
GeneratedAt time.Time `json:"generated_at"`
TotalErrors int `json:"total_errors"`
Statistics ErrorStats `json:"statistics"`
Errors []*BundleError `json:"errors"`
}
ErrorReport represents a collection of errors with statistics
type ErrorReporter ¶
type ErrorReporter interface {
Report(ctx context.Context, err *BundleError) error
GenerateReport(ctx context.Context, errors []*BundleError) (*ErrorReport, error)
GenerateErrorReport(ctx context.Context, errors []*BundleError, outputPath string) error
}
ErrorReporter defines the interface for error reporting
type ErrorSeverity ¶
type ErrorSeverity string
ErrorSeverity represents the severity of an error
const ( LowSeverity ErrorSeverity = "low" MediumSeverity ErrorSeverity = "medium" HighSeverity ErrorSeverity = "high" CriticalSeverity ErrorSeverity = "critical" )
Error severities
func GetErrorSeverity ¶
func GetErrorSeverity(err error) ErrorSeverity
GetErrorSeverity returns the severity of an error
type ErrorStats ¶ added in v0.8.0
type ErrorStats struct {
BySeverity map[string]int `json:"by_severity"`
ByCategory map[string]int `json:"by_category"`
ByRecoverability map[string]int `json:"by_recoverability"`
}
ErrorStats contains error statistics
type FileSystemRecoveryStrategy ¶
type FileSystemRecoveryStrategy struct {
// Logger is the logger for recovery events
Logger io.Writer
}
FileSystemRecoveryStrategy implements recovery strategies for file system errors
func NewFileSystemRecoveryStrategy ¶
func NewFileSystemRecoveryStrategy(logger io.Writer) *FileSystemRecoveryStrategy
NewFileSystemRecoveryStrategy creates a new file system recovery strategy
func (*FileSystemRecoveryStrategy) CanRecover ¶
func (s *FileSystemRecoveryStrategy) CanRecover(err *BundleError) bool
CanRecover determines if the strategy can recover from an error
func (*FileSystemRecoveryStrategy) Recover ¶
func (s *FileSystemRecoveryStrategy) Recover(ctx context.Context, err *BundleError) (bool, error)
Recover attempts to recover from a file system error
type NetworkRecoveryStrategy ¶
type NetworkRecoveryStrategy struct {
// Logger is the logger for recovery events
Logger io.Writer
// MaxRetries is the maximum number of retries
MaxRetries int
}
NetworkRecoveryStrategy implements recovery strategies for network errors
func NewNetworkRecoveryStrategy ¶
func NewNetworkRecoveryStrategy(logger io.Writer, maxRetries int) *NetworkRecoveryStrategy
NewNetworkRecoveryStrategy creates a new network recovery strategy
func (*NetworkRecoveryStrategy) CanRecover ¶
func (s *NetworkRecoveryStrategy) CanRecover(err *BundleError) bool
CanRecover determines if the strategy can recover from an error
func (*NetworkRecoveryStrategy) Recover ¶
func (s *NetworkRecoveryStrategy) Recover(ctx context.Context, err *BundleError) (bool, error)
Recover attempts to recover from a network error
type RecoveryManager ¶
type RecoveryManager struct {
// Strategies is a list of recovery strategies
Strategies []RecoveryStrategy
// Logger is the logger for recovery events
Logger io.Writer
// AuditLogger is the logger for audit events
AuditLogger *AuditLogger
}
RecoveryManager manages multiple recovery strategies
func NewRecoveryManager ¶
func NewRecoveryManager(logger io.Writer, auditLogger *AuditLogger) *RecoveryManager
NewRecoveryManager creates a new recovery manager
func (*RecoveryManager) AddStrategy ¶
func (m *RecoveryManager) AddStrategy(strategy RecoveryStrategy)
AddStrategy adds a recovery strategy to the manager
func (*RecoveryManager) AttemptRecovery ¶
func (m *RecoveryManager) AttemptRecovery(ctx context.Context, err *BundleError) (bool, error)
AttemptRecovery attempts to recover from an error using all available strategies
type RecoveryStrategy ¶
type RecoveryStrategy interface {
// Recover attempts to recover from an error
Recover(ctx context.Context, err *BundleError) (bool, error)
// CanRecover determines if the strategy can recover from an error
CanRecover(err *BundleError) bool
}
RecoveryStrategy defines the interface for error recovery strategies
type RetryPolicy ¶ added in v0.8.0
type RetryPolicy struct {
// MaxRetries is the maximum number of retries
MaxRetries int
// InitialDelay is the initial delay between retries
InitialDelay time.Duration
// MaxDelay is the maximum delay between retries
MaxDelay time.Duration
// Multiplier is the delay multiplier
Multiplier float64
// Jitter adds randomness to delays
Jitter bool
}
RetryPolicy defines retry behavior
func NewRetryPolicy ¶ added in v0.8.0
func NewRetryPolicy(maxRetries int, initialDelay, maxDelay time.Duration) *RetryPolicy
NewRetryPolicy creates a new retry policy
type TokenBucketRateLimiter ¶ added in v0.8.0
type TokenBucketRateLimiter struct {
// Capacity is the bucket capacity
Capacity int
// RefillRate is the token refill rate
RefillRate int
// Tokens is the current token count
Tokens int
// LastRefill is the last refill time
LastRefill time.Time
// contains filtered or unexported fields
}
TokenBucketRateLimiter implements token bucket rate limiting
func NewTokenBucketRateLimiter ¶ added in v0.8.0
func NewTokenBucketRateLimiter(capacity, refillRate int) *TokenBucketRateLimiter
NewTokenBucketRateLimiter creates a new token bucket rate limiter
func (*TokenBucketRateLimiter) Allow ¶ added in v0.8.0
func (rl *TokenBucketRateLimiter) Allow() bool
Allow checks if an operation is allowed