errutil

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: AGPL-3.0 Imports: 5 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

errutil

Documentation

Index

Constants

View Source
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

View Source
var ErrRateLimited = errors.New("rate limited")

Functions

func EnsureSuccess

func EnsureSuccess(err error, operation string)

func HandleConfigError

func HandleConfigError(operation, path string, fn func() error) error

func HandleDiscordError

func HandleDiscordError(operation string, fn func() error) error

func HandleValidationError

func HandleValidationError(field string, fn func() error) error

Convenience functions using global error handler

func InitializeGlobalErrorHandler

func InitializeGlobalErrorHandler(logger *logutil.Logger) error

InitializeGlobalErrorHandler initializes the global error handler

func IsRetryableError

func IsRetryableError(err error) bool

IsRetryableError determines if an error can be retried

func LogAndWrapError

func LogAndWrapError(err error, operation string, fields map[string]interface{}) error

func RetryOperation

func RetryOperation(ctx context.Context, operation string, maxAttempts int, fn func() error) error

Types

type ConfigError

type ConfigError struct {
	Operation string
	Path      string
	Cause     error
}

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

type DiscordError struct {
	Operation string
	Code      int
	Message   string
	Cause     error
}

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

type ValidationError struct {
	Field   string
	Value   interface{}
	Message string
}

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

Jump to

Keyboard shortcuts

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