Unified error handling for EasyRpc library.
Provides structured errors with typed categories, optional detail metadata, and helpers for creation, logging, formatting, and wrapping raw exceptions.
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 the error as a human-readable string.
Logs the error at the given level (default :error).
Creates a node error.
Raises an error by type + message, or directly from an existing %EasyRpc.Error{}.
Creates an RPC error.
Creates a timeout error.
Creates a validation error.
Wraps a rescued exception into an EasyRpc.Error, preserving the original
struct name in :details.
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 the error as a human-readable string.
Examples
iex> EasyRpc.Error.format(EasyRpc.Error.config_error("Invalid timeout"))
"[config_error] Invalid timeout"
iex> EasyRpc.Error.format(EasyRpc.Error.rpc_error("Refused", node: :n1@h))
"[rpc_error] Refused | details: [node: :n1@h]"
@spec log(t(), :error | :warning | :info | :debug) :: :ok
Logs the error at the given level (default :error).
Creates a node error.
@spec raise!(error_type(), String.t(), keyword()) :: no_return()
Raises an error by type + message, or directly from an existing %EasyRpc.Error{}.
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 rescued exception into an EasyRpc.Error, preserving the original
struct name in :details.
Examples
try do
:erpc.call(node, mod, fun, args)
rescue
e -> EasyRpc.Error.wrap_exception(e, node: node)
end