Skip to content

Violation of the Swarm.Distribution.Strategy definition is actually accepted #140

@balena

Description

@balena

{:error, {:invalid_ring, :no_nodes}} ->

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions