Raxol.Core.ErrorHandler (Raxol v2.0.1)
View SourceCentralized error handling module for the Raxol application.
Provides consistent error handling, logging, and recovery mechanisms across all modules in the system.
Features
- Standardized error types and messages
- Automatic error logging with context
- Graceful degradation strategies
- Error recovery mechanisms
- Telemetry integration for error monitoring
Usage
import Raxol.Core.ErrorHandler
# Handle errors with automatic logging
with_error_handling :file_operation do
File.read!("/path/to/file")
end
# Custom error recovery
handle_error {:error, :not_found}, default: "default_value"
Summary
Functions
Creates a standardized error tuple.
Executes a function with error handling.
Handles an error result with optional recovery.
Creates a supervisor-friendly error handler for GenServer processes.
Logs an error with context.
Converts various error formats to standardized format.
Chains multiple operations with error handling.
Wraps a function call with error handling and logging.
Types
@type error_context() :: map()
@type error_result() :: {:error, error_type(), String.t()} | {:error, error_type(), String.t(), error_context()}
@type error_severity() :: :debug | :info | :warning | :error | :critical
@type error_type() ::
:validation
| :runtime
| :system
| :network
| :permission
| :not_found
| :timeout
Functions
Creates a standardized error tuple.
Examples
error(:validation, "Invalid email format")
error(:not_found, "User not found", %{user_id: 123})
Executes a function with error handling.
Handles an error result with optional recovery.
Examples
result
|> handle_error(default: "fallback")
|> handle_error(with: fn error -> recover(error) end)
Creates a supervisor-friendly error handler for GenServer processes.
Logs an error with context.
Converts various error formats to standardized format.
Chains multiple operations with error handling.
Examples
pipeline do
step :validate_input, &validate/1
step :process_data, &process/1
step :save_result, &save/1
end
Wraps a function call with error handling and logging.
Options
:context- Additional context to log with errors:severity- Error severity level (default: :error):fallback- Fallback value on error:retry- Number of retry attempts (default: 0):retry_delay- Delay between retries in ms (default: 1000)
Examples
with_error_handling(:database_query, context: %{user_id: 123}) do
Repo.get!(User, user_id)
end