errors

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecoverWithContext

func RecoverWithContext(_ context.Context, operation string) error

RecoverWithContext handles panics and converts them to errors

func WithGracefulDegrade

func WithGracefulDegrade[T any](operation string, config *GracefulDegradeConfig, defaultVal T, fn func() (T, error)) T

WithGracefulDegrade executes a function and returns a default value on error

func WithRecover

func WithRecover(operation string, fn func() error) (err error)

WithRecover executes a function with panic recovery

func WithRetry

func WithRetry(ctx context.Context, operation string, config *RetryConfig, fn func() error) error

WithRetry executes a function with retry logic using retry-go

func WithRetryTyped

func WithRetryTyped[T any](
	ctx context.Context,
	operation string,
	config *RetryConfig,
	fn func() (T, error),
) (T, error)

WithRetryTyped executes a function with retry logic and returns a typed result

Types

type CircuitBreakerConfig

type CircuitBreakerConfig struct {
	FailureThreshold uint          // Number of failures before opening circuit
	SuccessThreshold uint          // Number of successes before closing circuit
	Timeout          time.Duration // Time to wait before attempting to close circuit
}

CircuitBreakerConfig configures circuit breaker behavior

func DefaultCircuitBreakerConfig

func DefaultCircuitBreakerConfig() *CircuitBreakerConfig

DefaultCircuitBreakerConfig returns sensible defaults

type GracefulDegradeConfig

type GracefulDegradeConfig struct {
	LogWarning bool
}

GracefulDegradeConfig configures graceful degradation behavior

type RetryConfig

type RetryConfig struct {
	MaxAttempts     uint
	InitialDelay    time.Duration
	MaxDelay        time.Duration
	Multiplier      float64
	RetryableErrors []string // Error codes that should trigger retry
}

RetryConfig configures retry behavior

func DefaultRetryConfig

func DefaultRetryConfig() *RetryConfig

DefaultRetryConfig returns sensible defaults

Jump to

Keyboard shortcuts

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