diff --git a/lib/nebulex/exceptions.ex b/lib/nebulex/exceptions.ex index c756bf07..5a278484 100644 --- a/lib/nebulex/exceptions.ex +++ b/lib/nebulex/exceptions.ex @@ -79,19 +79,19 @@ defmodule Nebulex.RPCError do Raised at runtime when a RPC error occurs. """ - @type t :: %__MODULE__{reason: atom} + @type t :: %__MODULE__{reason: atom, node: node} - defexception [:reason] + defexception [:reason, :node] @impl true - def message(%__MODULE__{reason: reason}) do - format_reason(reason) + def message(%__MODULE__{reason: reason, node: node}) do + format_reason(reason, node) end # :erpc.call/5 doesn't format error messages. - defp format_reason({:erpc, _} = reason) do + defp format_reason({:erpc, _} = reason, node) do """ - The RPC operation failed with reason: + The RPC operation failed on node #{inspect(node)} with reason: #{inspect(reason)} diff --git a/lib/nebulex/rpc.ex b/lib/nebulex/rpc.ex index 9b809cbc..21f42312 100644 --- a/lib/nebulex/rpc.ex +++ b/lib/nebulex/rpc.ex @@ -146,7 +146,7 @@ defmodule Nebulex.RPC do :erlang.raise(:error, original, __STACKTRACE__) other -> - reraise %Nebulex.RPCError{reason: other}, __STACKTRACE__ + reraise %Nebulex.RPCError{reason: other, node: node}, __STACKTRACE__ end end diff --git a/test/nebulex/adapters/partitioned_test.exs b/test/nebulex/adapters/partitioned_test.exs index eec3586e..5bd6f401 100644 --- a/test/nebulex/adapters/partitioned_test.exs +++ b/test/nebulex/adapters/partitioned_test.exs @@ -242,7 +242,10 @@ defmodule Nebulex.Adapters.PartitionedTest do assert Partitioned.put(1, 1) == :ok assert Partitioned.get(1, timeout: 1000) == 1 - msg = ~r"The RPC operation failed with reason:\n\n{:erpc, :timeout}" + node = "#{inspect(Partitioned.get_node(1))}" + reason = "#{inspect({:erpc, :timeout})}" + + msg = ~r"The RPC operation failed on node #{node} with reason:\n\n#{reason}" assert_raise Nebulex.RPCError, msg, fn -> Partitioned.get(1, timeout: 0)