Thin :erpc boundary that normalizes every distributed failure into a
SuperCache.Cluster.Error.
Call sites should use this module instead of calling :erpc directly so
that node-down, timeout, remote-exception, exit, and throw reasons all
reach callers in the same shape.
API
call/5— returns{:ok, value}or{:error, %Error{}}.call!/5— returnsvalueor raises%Error{}.normalize/2— converts a raw reason and context into%Error{}.
Context
The fifth argument (or the second argument to normalize/2) is a keyword
list or map with optional fields:
:operation— defaults to{module, function}from the call.:partition— partition index, when the operation targets one.:node— defaults to the node being called.:mode— replication or read mode active for the operation.:timeout—:erpctimeout in milliseconds; defaults to5_000.
Examples
Rpc.call(primary, __MODULE__, :local_read, [0, :get, :key],
partition: 0, mode: :primary)
# => {:ok, [{:key, "value"}]}
Rpc.call(unreachable, __MODULE__, :local_read, [0, :get, :key],
partition: 0, mode: :primary)
# => {:error, %SuperCache.Cluster.Error{reason: :noconnection, ...}}
Rpc.call!(primary, __MODULE__, :local_read, [0, :get, :key])
# raises %SuperCache.Cluster.Error{} when the call fails
Summary
Functions
Call module.function(args) on node with a normalized error result.
Call module.function(args) on node, raising %SuperCache.Cluster.Error{}
when the call fails.
Normalize a raw :erpc or process reason into a SuperCache.Cluster.Error.
Functions
@spec call(node(), module(), atom(), list(), keyword() | map()) :: {:ok, term()} | {:error, SuperCache.Cluster.Error.t()}
Call module.function(args) on node with a normalized error result.
The function consolidates :erpc exceptions, exits, throws, timeouts,
and disconnections into {:error, %SuperCache.Cluster.Error{}}. A
successful remote return of {:error, reason} is treated as a value and
returned as {:ok, {:error, reason}}, because it is not a transport
failure.
Call module.function(args) on node, raising %SuperCache.Cluster.Error{}
when the call fails.
@spec normalize(term(), keyword() | map()) :: SuperCache.Cluster.Error.t()
Normalize a raw :erpc or process reason into a SuperCache.Cluster.Error.
Recognized reasons include :nodedown, :noconnection, :timeout,
{:erpc, reason}, {:exception, class, reason, stack},
{:exception, reason, stack}, {:exit, reason}, {:throw, reason}, and
any non-exception term.
An existing %SuperCache.Cluster.Error{} is returned with any context
fields that are still nil filled in.