Documentation
¶
Index ¶
- Variables
- func InfiniteLoop(f func() error, config *RetryConfig, exceptions ...string)
- func InfiniteRetry(f func() error, config *RetryConfig, exceptions ...string) error
- func InfiniteRetryIfXError(f func() error, config *RetryConfig, exception string) error
- func Info(msg string, args map[string]any)
- func IsException(err error, exceptions ...string) bool
- func IsSdkException(err *SdkError, exceptions ...string) bool
- func Retry(f func() error, config *RetryConfig, exceptions ...string) error
- func RetryWithBackoff(f func() error, config *RetryConfig, maxBackoff time.Duration, ...) error
- type RetryConfig
- type SdkError
- type SdkLog
Constants ¶
This section is empty.
Variables ¶
var DefaultRetryConfig = &RetryConfig{ MaxRetries: 5, WaitTime: 1 * time.Second, }
DefaultRetryConfig provides sensible defaults for retry operations
Functions ¶
func InfiniteLoop ¶ added in v1.0.29
func InfiniteLoop(f func() error, config *RetryConfig, exceptions ...string)
InfiniteLoop continuously executes a provided function until it produces a matching exception error. Enhanced version of logger.InfiniteLoop for catcher system.
Parameters:
- f: Function to execute repeatedly
- config: Configuration for wait time and logging (MaxRetries is ignored)
- exceptions: Error patterns that should stop the loop
func InfiniteRetry ¶ added in v1.0.29
func InfiniteRetry(f func() error, config *RetryConfig, exceptions ...string) error
InfiniteRetry executes a function repeatedly until it succeeds or returns an error containing specified exception patterns. Enhanced version of logger.InfiniteRetry.
Parameters:
- f: Function to execute that returns an error
- config: Retry configuration (MaxRetries is ignored, use nil for defaults)
- exceptions: Error patterns that should stop retrying immediately
Returns:
- error: nil on success, error on exception match
func InfiniteRetryIfXError ¶ added in v1.0.29
func InfiniteRetryIfXError(f func() error, config *RetryConfig, exception string) error
InfiniteRetryIfXError retries a function f() infinitely only if the error returned matches the specified exception. Enhanced version of logger.InfiniteRetryIfXError.
This function provides advanced error filtering: - Retries only if error matches the specific exception - Returns immediately on different errors or success - Logs the exception only once to avoid log saturation - Logs when the issue is resolved
Parameters:
- f: Function to execute that returns an error
- config: Retry configuration (MaxRetries is ignored)
- exception: Specific error pattern to retry on
Returns:
- error: nil on success, non-matching error immediately, or context error
func Info ¶ added in v1.0.29
Info logs a message with a unique code, stack trace, and optional contextual arguments in a structured format.
func IsException ¶ added in v1.0.29
IsException checks if an error matches any of the specified exception patterns
func IsSdkException ¶ added in v1.0.29
IsSdkException checks if an SdkError matches any of the specified exception patterns This provides enhanced checking for SdkError types including message and cause
func Retry ¶ added in v1.0.29
func Retry(f func() error, config *RetryConfig, exceptions ...string) error
Retry executes a function repeatedly until it succeeds, the maximum retries are reached, or a matching exception is encountered. Enhanced version of logger.Retry for catcher system.
Parameters:
- f: Function to execute that returns an error
- config: Retry configuration (use nil for defaults)
- exceptions: Error patterns that should stop retrying immediately
Returns:
- error: nil on success, last error on failure or exception match
func RetryWithBackoff ¶ added in v1.0.29
func RetryWithBackoff(f func() error, config *RetryConfig, maxBackoff time.Duration, backoffMultiplier float64, exceptions ...string) error
RetryWithBackoff executes a function with exponential backoff retry strategy. This is a new enhanced retry function not available in the original logger.
Parameters:
- f: Function to execute that returns an error
- config: Base retry configuration
- maxBackoff: Maximum backoff duration
- backoffMultiplier: Multiplier for exponential backoff (typically 2.0)
- exceptions: Error patterns that should stop retrying immediately
Returns:
- error: nil on success, last error on failure or exception match
Types ¶
type RetryConfig ¶ added in v1.0.29
type RetryConfig struct {
MaxRetries int // Maximum number of retries (0 = infinite)
WaitTime time.Duration // Wait time between retries
}
RetryConfig defines configuration options for retry operations
type SdkError ¶
type SdkError struct {
Code string `json:"code"`
Trace []string `json:"trace"`
Msg string `json:"msg"`
Cause *string `json:"cause,omitempty"`
Args map[string]any `json:"args,omitempty"`
}
SdkError is a struct that implements the Go error interface.
func Error ¶
Error tries to cast the cause as an SdkError, if it is not an SdkError, it creates a new SdkError with the given parameters. It logs the error message and returns the error. If cause is nil, it will store a blank string in the Cause field. The field Code is a hash of the message and trace. It is used to identify the recurrence of an error. Params: msg: the error message. cause: the error that caused this error. args: a map of additional information. Returns: *SdkError: the error. This type implements the Go error interface.
func ToSdkError ¶
ToSdkError tries to cast an error to a SdkError. If the error isn't an SdkError, it returns nil.