Skip to content

Commit

Permalink
Add :node to the Nebulex.RPCError
Browse files Browse the repository at this point in the history
  • Loading branch information
cabol committed Oct 30, 2021
1 parent 766a6a3 commit b8f01cf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/nebulex/exceptions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
2 changes: 1 addition & 1 deletion lib/nebulex/rpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion test/nebulex/adapters/partitioned_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b8f01cf

Please sign in to comment.