Raxol.Core.Utils.ErrorPatterns (Raxol v2.0.1)

View Source

Consolidated error handling patterns used throughout the Raxol codebase. Provides consistent error handling, logging, and recovery mechanisms.

Summary

Functions

Common pattern for handling call timeouts.

Standardized way to handle GenServer initialization errors.

Standardized error recovery with exponential backoff.

Validates input parameters with common validation patterns.

Common pattern for resource cleanup on errors.

Wraps a function call with standardized error handling and logging.

Types

error_reason()

@type error_reason() :: atom() | String.t() | term()

result(success)

@type result(success) :: {:ok, success} | {:error, error_reason()}

Functions

call_with_timeout(server, request, timeout \\ 5000)

@spec call_with_timeout(GenServer.server(), any(), timeout()) :: result(any())

Common pattern for handling call timeouts.

init_with_validation(args, validator_func)

@spec init_with_validation(any(), (any() -> result(any()))) ::
  {:ok, any()} | {:stop, any()}

Standardized way to handle GenServer initialization errors.

retry_with_backoff(func, opts \\ [])

@spec retry_with_backoff(
  (-> result(any())),
  keyword()
) :: result(any())

Standardized error recovery with exponential backoff.

validate_params(params, required_keys)

@spec validate_params(map(), list()) :: :ok | {:error, error_reason()}

Validates input parameters with common validation patterns.

with_cleanup(func, cleanup_func)

@spec with_cleanup((-> result(any())), (-> :ok)) :: result(any())

Common pattern for resource cleanup on errors.

with_error_handling(func, opts \\ [])

@spec with_error_handling(
  (-> any()),
  keyword()
) :: result(any())

Wraps a function call with standardized error handling and logging.