anoma / green

https://anoma.github.io/anoma/
MIT License
7 stars 0 forks source link

Use `Keyword.validate!` in Anoma.Node #537

Closed mariari closed 2 months ago

mariari commented 5 months ago

customer: performer: deadline: estimated: started: actual: completed: confirmed: dependencies:

I'm refactoring some of the startup code, and I notice it doesn't catch wrong keywords getting in. We should use Keyword.validate!/2 to ensure we aren't passing wrong arguments.

This is mainly useful in refactoring, as tests will catch wrong arguments passing things in.

mariari commented 2 months ago

For example in the Anoma.Node we have the following

  @spec start_link(configuration()) :: GenServer.on_start()
  def start_link(args) do
    # strawman pending proper lockfiles
    # also need to clean this up once we're done
    unix_path = Anoma.System.Directories.data("local.sock")

    testing = args[:testing] || false
    should_socket? = Mix.env() in [:dev, :prod] and not testing

  ...
  end

We aren't using Keyword.validate! like we do in other places in our code, it should resemble the following

  def launch_min(parsed_map, options \\ []) do
    keys =
      Keyword.validate!(options,
        supervisor: nil,
        use_rocksdb: false,
        testing: false
      )

    node_settings = parsed_map |> node_settings()
    settings = Anoma.Node.start_min(node_settings)
    ...
    end

instead

mariari commented 2 months ago

We have work in that makes this already done, however I'd argue this is stale given the code changes in the V0.22.0 release that overhauls the codebase