By definition, Swarm.Distribution.Strategy.key_to_node/2 can return node() | :undefined. However this exact line is actually accepting {:error, {:invalid_ring, :no_nodes}} as a valid return value, which is actually what HashRing.key_to_node/2 returns in case of error.
So Swarm.Distribution.Ring.key_to_node/2 should actually return :undefined instead of {:error, reason} to honour the strategy definition:
defmodule Swarm.Distribution.Ring do
...
def key_to_node(ring, key) do
case HashRing.key_to_node(ring, key) do
{:error, _reason} -> :undefined
node -> node
end
end
end
https://github.com/bitwalker/swarm/blob/4aee63d83ad5ee6ee095b38b3ff93a4dbb7c3400/lib/swarm/tracker/tracker.ex#L1187
By definition,
Swarm.Distribution.Strategy.key_to_node/2
can returnnode() | :undefined
. However this exact line is actually accepting{:error, {:invalid_ring, :no_nodes}}
as a valid return value, which is actually whatHashRing.key_to_node/2
returns in case of error.So
Swarm.Distribution.Ring.key_to_node/2
should actually return:undefined
instead of{:error, reason}
to honour the strategy definition: