EasyRpc.Error exception (EasyRpc v0.6.0)
View SourceUnified error handling for EasyRpc library.
This module provides structured error handling with different error types and helper functions for error creation, logging, and formatting.
Error Types
:config_error- Configuration validation errors:rpc_error- Remote procedure call errors:node_error- Node selection or availability errors:timeout_error- RPC timeout errors:validation_error- Input validation errors
Examples
iex> EasyRpc.Error.config_error("Invalid timeout value")
%EasyRpc.Error{type: :config_error, message: "Invalid timeout value", details: nil}
iex> EasyRpc.Error.rpc_error("Connection refused", node: :node1@host)
%EasyRpc.Error{type: :rpc_error, message: "Connection refused", details: [node: :node1@host]}
Summary
Functions
Creates a configuration error.
Formats an error into a human-readable string.
Logs an error using Logger.
Creates a node error.
Raises an error with the given type and message.
Creates an RPC error.
Creates a timeout error.
Creates a validation error.
Wraps a caught exception into an EasyRpc.Error.
Types
@type error_type() ::
:config_error | :rpc_error | :node_error | :timeout_error | :validation_error
@type t() :: %EasyRpc.Error{ __exception__: true, details: keyword() | map() | nil, message: String.t(), type: error_type() }
Functions
Creates a configuration error.
Formats an error into a human-readable string.
Examples
iex> error = EasyRpc.Error.config_error("Invalid timeout")
iex> EasyRpc.Error.format(error)
"[EasyRpc.Error:config_error] Invalid timeout"
@spec log(t(), :error | :warning | :info | :debug) :: :ok
Logs an error using Logger.
Examples
EasyRpc.Error.log(error, :error)
EasyRpc.Error.log(error, :warning)
Creates a node error.
@spec raise!(error_type(), String.t(), keyword()) :: no_return()
Raises an error with the given type and message.
Examples
EasyRpc.Error.raise!(:config_error, "Invalid config")
EasyRpc.Error.raise!(error_struct)
Creates an RPC error.
Creates a timeout error.
Creates a validation error.
@spec wrap_exception( Exception.t(), keyword() ) :: t()
Wraps a caught exception into an EasyRpc.Error.
Examples
try do
:erpc.call(node, mod, fun, args)
rescue
e -> EasyRpc.Error.wrap_exception(e, node: node)
end