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 WithRetry(ctx context.Context, handler ErrorHandler, fn func() error) error
- func WithRetryAndContext(ctx context.Context, handler *EnhancedErrorHandler, fn func() error) error
- func WrapError(err error, message string) 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
- type ConflictRecoveryStrategy
- type DefaultErrorCategorizer
- type DefaultErrorHandler
- func (h *DefaultErrorHandler) GetBackoffDuration(ctx context.Context, err *BundleError) time.Duration
- func (h *DefaultErrorHandler) HandleError(ctx context.Context, err error) (*BundleError, error)
- func (h *DefaultErrorHandler) LogError(ctx context.Context, err *BundleError)
- func (h *DefaultErrorHandler) NotifyAdmin(ctx context.Context, err *BundleError) error
- func (h *DefaultErrorHandler) ShouldRetry(ctx context.Context, err *BundleError) bool
- type DefaultErrorReporter
- func (r *DefaultErrorReporter) GenerateErrorReport(ctx context.Context, errors []*BundleError, outputPath string) error
- func (r *DefaultErrorReporter) GetErrorStatistics(errors []*BundleError) map[string]interface{}
- func (r *DefaultErrorReporter) ReportError(ctx context.Context, bundleErr *BundleError) error
- type EmailNotificationService
- type EnhancedErrorHandler
- func (h *EnhancedErrorHandler) GetBackoffDuration(ctx context.Context, err *BundleError) time.Duration
- func (h *EnhancedErrorHandler) GetErrorMetrics() *ErrorMetrics
- func (h *EnhancedErrorHandler) HandleError(ctx context.Context, err error) (*BundleError, error)
- func (h *EnhancedErrorHandler) LogError(ctx context.Context, err *BundleError)
- func (h *EnhancedErrorHandler) NotifyAdmin(ctx context.Context, err *BundleError) error
- func (h *EnhancedErrorHandler) ResetErrorMetrics()
- func (h *EnhancedErrorHandler) ShouldRetry(ctx context.Context, err *BundleError) bool
- type ErrorCategorizer
- type ErrorCategory
- type ErrorHandler
- type ErrorLogger
- type ErrorMetrics
- type ErrorRecoverability
- type ErrorReport
- type ErrorReporter
- type ErrorSeverity
- type FileSystemRecoveryStrategy
- type NetworkRecoveryStrategy
- type NotificationService
- type RecoveryManager
- type RecoveryStrategy
- type SlackNotificationService
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 WithRetry ¶
func WithRetry(ctx context.Context, handler ErrorHandler, fn func() error) error
WithRetry executes a function with retry logic
func WithRetryAndContext ¶
func WithRetryAndContext(ctx context.Context, handler *EnhancedErrorHandler, fn func() error) error
WithRetryAndContext executes a function with enhanced retry logic and context awareness
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 {
// Original is the original error
Original error
// Message is a human-readable error message
Message string
// Category is the category of the error
Category ErrorCategory
// Severity is the severity of the error
Severity ErrorSeverity
// Recoverability indicates whether the error is recoverable
Recoverability ErrorRecoverability
// Context contains additional context about the error
Context map[string]interface{}
// ErrorID is a unique identifier for the error
ErrorID string
// Timestamp is the time the error occurred
Timestamp time.Time
// RetryAttempt is the current retry attempt
RetryAttempt int
// MaxRetries is the maximum number of retries
MaxRetries int
}
BundleError represents a structured error with additional metadata
func NewBundleError ¶
func NewBundleError(err error, message string, category ErrorCategory, severity ErrorSeverity, recoverability ErrorRecoverability) *BundleError
NewBundleError creates a new bundle error
func (*BundleError) WithContext ¶
func (e *BundleError) WithContext(key string, value interface{}) *BundleError
WithContext adds context to the error
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 handling
Logger ErrorLogger
// AdminNotificationEnabled indicates whether admin notifications are enabled
AdminNotificationEnabled bool
// AdminEmail is the email address for admin notifications
AdminEmail string
}
DefaultErrorHandler is the default implementation of ErrorHandler
func (*DefaultErrorHandler) GetBackoffDuration ¶
func (h *DefaultErrorHandler) GetBackoffDuration(ctx context.Context, err *BundleError) time.Duration
GetBackoffDuration returns the backoff duration for a retry
func (*DefaultErrorHandler) HandleError ¶
func (h *DefaultErrorHandler) HandleError(ctx context.Context, err error) (*BundleError, error)
HandleError handles an error
func (*DefaultErrorHandler) LogError ¶
func (h *DefaultErrorHandler) LogError(ctx context.Context, err *BundleError)
LogError logs an error
func (*DefaultErrorHandler) NotifyAdmin ¶
func (h *DefaultErrorHandler) NotifyAdmin(ctx context.Context, err *BundleError) error
NotifyAdmin notifies an administrator about a critical error
func (*DefaultErrorHandler) ShouldRetry ¶
func (h *DefaultErrorHandler) ShouldRetry(ctx context.Context, err *BundleError) bool
ShouldRetry determines whether an error should be retried
type DefaultErrorReporter ¶
type DefaultErrorReporter struct {
// Logger is the logger for error reporting
Logger io.Writer
// ReportsDir is the directory for error reports
ReportsDir string
// NotificationService is the service for sending notifications
NotificationService NotificationService
// IncludeSystemInfo indicates whether to include system information in reports
IncludeSystemInfo bool
}
DefaultErrorReporter is the default implementation of ErrorReporter
func (*DefaultErrorReporter) GenerateErrorReport ¶
func (r *DefaultErrorReporter) GenerateErrorReport(ctx context.Context, errors []*BundleError, outputPath string) error
GenerateErrorReport generates an error report for a list of errors
func (*DefaultErrorReporter) GetErrorStatistics ¶
func (r *DefaultErrorReporter) GetErrorStatistics(errors []*BundleError) map[string]interface{}
GetErrorStatistics returns statistics about errors
func (*DefaultErrorReporter) ReportError ¶
func (r *DefaultErrorReporter) ReportError(ctx context.Context, bundleErr *BundleError) error
ReportError reports an error
type EmailNotificationService ¶
type EmailNotificationService struct {
// Recipients is the list of email recipients
Recipients []string
// SenderEmail is the sender email address
SenderEmail string
// SMTPServer is the SMTP server
SMTPServer string
// SMTPPort is the SMTP port
SMTPPort int
// SMTPUsername is the SMTP username
SMTPUsername string
// SMTPPassword is the SMTP password
SMTPPassword string
// Logger is the logger for notification events
Logger io.Writer
}
EmailNotificationService implements NotificationService for email notifications
func NewEmailNotificationService ¶
func NewEmailNotificationService(recipients []string, senderEmail, smtpServer string, smtpPort int, logger io.Writer) *EmailNotificationService
NewEmailNotificationService creates a new email notification service
func (*EmailNotificationService) SendNotification ¶
func (s *EmailNotificationService) SendNotification(ctx context.Context, subject, message string) error
SendNotification sends an email notification
type EnhancedErrorHandler ¶
type EnhancedErrorHandler struct {
DefaultErrorHandler
// MaxRetries is the maximum number of retries for recoverable errors
MaxRetries int
// RetryableCategories is a list of error categories that are retryable
RetryableCategories map[ErrorCategory]bool
// BackoffBaseSeconds is the base time in seconds for exponential backoff
BackoffBaseSeconds float64
// BackoffMaxSeconds is the maximum backoff time in seconds
BackoffMaxSeconds float64
// BackoffJitterFactor is the jitter factor for backoff (0-1)
BackoffJitterFactor float64
// NotificationThreshold is the severity threshold for admin notifications
NotificationThreshold ErrorSeverity
// ErrorMetrics tracks error metrics for reporting
ErrorMetrics *ErrorMetrics
}
EnhancedErrorHandler extends the DefaultErrorHandler with advanced error handling capabilities
func NewEnhancedErrorHandler ¶
func NewEnhancedErrorHandler(logger ErrorLogger) *EnhancedErrorHandler
NewEnhancedErrorHandler creates a new enhanced error handler
func (*EnhancedErrorHandler) GetBackoffDuration ¶
func (h *EnhancedErrorHandler) GetBackoffDuration(ctx context.Context, err *BundleError) time.Duration
GetBackoffDuration returns the backoff duration for a retry with exponential backoff
func (*EnhancedErrorHandler) GetErrorMetrics ¶
func (h *EnhancedErrorHandler) GetErrorMetrics() *ErrorMetrics
GetErrorMetrics returns the current error metrics
func (*EnhancedErrorHandler) HandleError ¶
func (h *EnhancedErrorHandler) HandleError(ctx context.Context, err error) (*BundleError, error)
HandleError handles an error with enhanced categorization and tracking
func (*EnhancedErrorHandler) LogError ¶
func (h *EnhancedErrorHandler) LogError(ctx context.Context, err *BundleError)
LogError logs an error with enhanced details
func (*EnhancedErrorHandler) NotifyAdmin ¶
func (h *EnhancedErrorHandler) NotifyAdmin(ctx context.Context, err *BundleError) error
NotifyAdmin notifies an administrator about a critical error with enhanced details
func (*EnhancedErrorHandler) ResetErrorMetrics ¶
func (h *EnhancedErrorHandler) ResetErrorMetrics()
ResetErrorMetrics resets the error metrics
func (*EnhancedErrorHandler) ShouldRetry ¶
func (h *EnhancedErrorHandler) ShouldRetry(ctx context.Context, err *BundleError) bool
ShouldRetry determines whether an error should be retried with enhanced logic
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 defines the category of an error
const ( // ValidationError indicates an error during bundle validation ValidationError ErrorCategory = "validation" // FileSystemError indicates an error related to file system operations FileSystemError ErrorCategory = "filesystem" // NetworkError indicates an error related to network operations NetworkError ErrorCategory = "network" // ConfigurationError indicates an error related to configuration ConfigurationError ErrorCategory = "configuration" // PermissionError indicates an error related to permissions PermissionError ErrorCategory = "permission" // BackupError indicates an error related to backup operations BackupError ErrorCategory = "backup" // ConflictError indicates an error related to file conflicts ConflictError ErrorCategory = "conflict" // UnknownError indicates an error of unknown category UnknownError ErrorCategory = "unknown" )
func GetErrorCategory ¶
func GetErrorCategory(err error) ErrorCategory
GetErrorCategory returns the category of an error
type ErrorHandler ¶
type ErrorHandler interface {
// HandleError handles an error
HandleError(ctx context.Context, err error) (*BundleError, error)
// ShouldRetry determines whether an error should be retried
ShouldRetry(ctx context.Context, err *BundleError) bool
// GetBackoffDuration returns the backoff duration for a retry
GetBackoffDuration(ctx context.Context, err *BundleError) time.Duration
// LogError logs an error
LogError(ctx context.Context, err *BundleError)
// NotifyAdmin notifies an administrator about a critical error
NotifyAdmin(ctx context.Context, err *BundleError) error
}
ErrorHandler defines the interface for error handling
func NewErrorHandler ¶
func NewErrorHandler(logger ErrorLogger) ErrorHandler
NewErrorHandler creates a new error handler
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 is the total number of errors
TotalErrors int
// ErrorsByCategory tracks errors by category
ErrorsByCategory map[ErrorCategory]int
// ErrorsBySeverity tracks errors by severity
ErrorsBySeverity map[ErrorSeverity]int
// RecoveredErrors is the number of errors that were recovered from
RecoveredErrors int
// UnrecoveredErrors is the number of errors that were not recovered from
UnrecoveredErrors int
// RetryAttempts is the total number of retry attempts
RetryAttempts int
// SuccessfulRetries is the number of successful retries
SuccessfulRetries int
}
ErrorMetrics tracks error statistics for reporting
type ErrorRecoverability ¶
type ErrorRecoverability string
ErrorRecoverability defines whether an error is recoverable
const ( // RecoverableError indicates an error that can be recovered from RecoverableError ErrorRecoverability = "recoverable" // NonRecoverableError indicates an error that cannot be recovered from NonRecoverableError ErrorRecoverability = "non-recoverable" )
type ErrorReport ¶
type ErrorReport struct {
// ReportID is the unique identifier for the report
ReportID string `json:"report_id"`
// Timestamp is the time the report was generated
Timestamp time.Time `json:"timestamp"`
// Errors is the list of errors in the report
Errors []*BundleError `json:"errors"`
// Statistics is the error statistics
Statistics map[string]interface{} `json:"statistics"`
// SystemInfo is information about the system
SystemInfo map[string]interface{} `json:"system_info"`
}
ErrorReport represents a structured error report
type ErrorReporter ¶
type ErrorReporter interface {
// ReportError reports an error
ReportError(ctx context.Context, err *BundleError) error
// GenerateErrorReport generates an error report for a list of errors
GenerateErrorReport(ctx context.Context, errors []*BundleError, outputPath string) error
// GetErrorStatistics returns statistics about errors
GetErrorStatistics(errors []*BundleError) map[string]interface{}
}
ErrorReporter defines the interface for error reporting
func NewErrorReporter ¶
func NewErrorReporter(logger io.Writer, reportsDir string) ErrorReporter
NewErrorReporter creates a new error reporter
type ErrorSeverity ¶
type ErrorSeverity string
ErrorSeverity defines the severity of an error
const ( // CriticalSeverity indicates a critical error that prevents the operation from continuing CriticalSeverity ErrorSeverity = "critical" // HighSeverity indicates a high severity error that may affect the operation HighSeverity ErrorSeverity = "high" // MediumSeverity indicates a medium severity error that should be addressed MediumSeverity ErrorSeverity = "medium" // LowSeverity indicates a low severity error that is not critical LowSeverity ErrorSeverity = "low" )
func GetErrorSeverity ¶
func GetErrorSeverity(err error) ErrorSeverity
GetErrorSeverity returns the severity of an error
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 NotificationService ¶
type NotificationService interface {
// SendNotification sends a notification
SendNotification(ctx context.Context, subject, message string) error
}
NotificationService defines the interface for sending notifications
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 SlackNotificationService ¶
type SlackNotificationService struct {
// WebhookURL is the Slack webhook URL
WebhookURL string
// Channel is the Slack channel
Channel string
// Username is the username to use for notifications
Username string
// Logger is the logger for notification events
Logger io.Writer
}
SlackNotificationService implements NotificationService for Slack notifications
func NewSlackNotificationService ¶
func NewSlackNotificationService(webhookURL, channel, username string, logger io.Writer) *SlackNotificationService
NewSlackNotificationService creates a new Slack notification service
func (*SlackNotificationService) SendNotification ¶
func (s *SlackNotificationService) SendNotification(ctx context.Context, subject, message string) error
SendNotification sends a Slack notification