Documentation
¶
Index ¶
- Constants
- Variables
- func EnsureSuccess(err error, operation string)
- func HandleConfigError(operation, path string, fn func() error) error
- func HandleDiscordError(operation string, fn func() error) error
- func HandleValidationError(field string, fn func() error) error
- func InitializeGlobalErrorHandler(logger *logutil.Logger) error
- func IsRetryableError(err error) bool
- func LogAndWrapError(err error, operation string, fields map[string]interface{}) error
- func RetryOperation(ctx context.Context, operation string, maxAttempts int, fn func() error) error
- type ConfigError
- type DiscordError
- type ErrorHandler
- func (eh *ErrorHandler) EnsureSuccess(err error, operation string)
- func (eh *ErrorHandler) HandleConfigError(operation, path string, fn func() error) error
- func (eh *ErrorHandler) HandleDiscordError(operation string, fn func() error) error
- func (eh *ErrorHandler) HandleValidationError(field string, fn func() error) error
- func (eh *ErrorHandler) HandleWithCleanup(operation string, fn func() error, cleanup func()) error
- func (eh *ErrorHandler) LogAndWrapError(err error, operation string, fields map[string]interface{}) error
- func (eh *ErrorHandler) RetryOperation(ctx context.Context, operation string, maxAttempts int, fn func() error) error
- type RetryManager
- type ValidationError
Constants ¶
const ( // Error messages ErrValidationFailed = "validation failed" ErrConfigOperationFailed = "configuration operation failed" ErrDiscordOperationFailed = "discord operation failed" ErrNonRetryable = "non-retryable error encountered" ErrGlobalLoggerNotInitialized = "global logger not initialized for error handler" ErrOnAttempt = "error on attempt %d for %s" ErrOperationAttemptsFailed = "operation %s failed after %d attempts. Last error: %w" // Constants for log messages MsgOperationRetrying = "operation failed, retrying" MsgOperationSucceededAfterRetry = "operation succeeded after retry" MsgOperationFailedAllRetries = "operation failed after all retries" MsgOperationFailedCleanup = "operation failed, running cleanup" ErrOperationFailed = "operation failed" MsgCriticalOperationFailed = "critical operation failed" // Constants for error format strings ErrFmtNonRetryable = "non-retryable error in %s: %w" ErrFmtOperationCancelled = "operation %s cancelled: %w" ErrFmtOperationFailedAfterRetries = "operation %s failed after %d attempts: %w" ErrFmtOperationFailed = "%s failed: %w" ErrFmtPanicCriticalOperationFailed = "critical operation %s failed: %v" )
Variables ¶
var ErrRateLimited = errors.New("rate limited")
Functions ¶
func EnsureSuccess ¶
func HandleConfigError ¶
func HandleDiscordError ¶
func HandleValidationError ¶
Convenience functions using global error handler
func InitializeGlobalErrorHandler ¶
InitializeGlobalErrorHandler initializes the global error handler
func IsRetryableError ¶
IsRetryableError determines if an error can be retried
func LogAndWrapError ¶
Types ¶
type ConfigError ¶
ConfigError represents configuration-related errors
func NewConfigError ¶
func NewConfigError(operation, path string, cause error) ConfigError
NewConfigError creates a new configuration error
func (ConfigError) Error ¶
func (e ConfigError) Error() string
func (ConfigError) Unwrap ¶
func (e ConfigError) Unwrap() error
type DiscordError ¶
DiscordError represents Discord API related errors
func NewDiscordError ¶
func NewDiscordError(operation string, code int, message string, cause error) DiscordError
NewDiscordError creates a new Discord API error
func (DiscordError) Error ¶
func (e DiscordError) Error() string
func (DiscordError) Unwrap ¶
func (e DiscordError) Unwrap() error
type ErrorHandler ¶
type ErrorHandler struct {
// contains filtered or unexported fields
}
ErrorHandler provides utilities for consistent error handling
var GlobalErrorHandler *ErrorHandler
Global error handler instance
func NewErrorHandler ¶
func NewErrorHandler(logger *logutil.Logger) *ErrorHandler
NewErrorHandler creates a new error handler
func (*ErrorHandler) EnsureSuccess ¶
func (eh *ErrorHandler) EnsureSuccess(err error, operation string)
EnsureSuccess panics if the error is not nil - use only for critical operations
func (*ErrorHandler) HandleConfigError ¶
func (eh *ErrorHandler) HandleConfigError(operation, path string, fn func() error) error
HandleConfigError wraps configuration operations with consistent error handling
func (*ErrorHandler) HandleDiscordError ¶
func (eh *ErrorHandler) HandleDiscordError(operation string, fn func() error) error
HandleDiscordError wraps Discord API operations with error handling
func (*ErrorHandler) HandleValidationError ¶
func (eh *ErrorHandler) HandleValidationError(field string, fn func() error) error
HandleValidationError wraps a function with validation error handling
func (*ErrorHandler) HandleWithCleanup ¶
func (eh *ErrorHandler) HandleWithCleanup(operation string, fn func() error, cleanup func()) error
HandleWithCleanup executes a function with cleanup on error
func (*ErrorHandler) LogAndWrapError ¶
func (eh *ErrorHandler) LogAndWrapError(err error, operation string, fields map[string]interface{}) error
LogAndWrapError logs an error with context and wraps it with additional message
func (*ErrorHandler) RetryOperation ¶
func (eh *ErrorHandler) RetryOperation(ctx context.Context, operation string, maxAttempts int, fn func() error) error
RetryOperation executes an operation with retry logic
type RetryManager ¶
type RetryManager struct {
// contains filtered or unexported fields
}
func NewRetryManager ¶
func NewRetryManager() *RetryManager
func (*RetryManager) ExecuteWithRetry ¶
func (rm *RetryManager) ExecuteWithRetry(operation func() error, operationName string) error
func (*RetryManager) SetBaseDelay ¶
func (rm *RetryManager) SetBaseDelay(delay time.Duration)
func (*RetryManager) SetMaxDelay ¶
func (rm *RetryManager) SetMaxDelay(delay time.Duration)
func (*RetryManager) SetMaxRetries ¶
func (rm *RetryManager) SetMaxRetries(retries int)
type ValidationError ¶
ValidationError represents a validation error with field context
func NewValidationError ¶
func NewValidationError(field string, value interface{}, message string) ValidationError
NewValidationError creates a new validation error
func (ValidationError) Error ¶
func (e ValidationError) Error() string