ash-project / reactor

Reactor is a dynamic, concurrent, dependency resolving saga orchestrator.
https://ash-hq.org/
MIT License
44 stars 6 forks source link

Switch emits cryptic error when following the docs #127

Closed ekosz closed 2 weeks ago

ekosz commented 2 weeks ago

Describe the bug When using a switch expression, one gets a cryptic error from seemingly correct configuration? EDIT: After some digging the error comes up if one does not supply a default branch to the switch statement.

To Reproduce

defmodule FooReactor do
  use Reactor

  input(:foo)

  switch :maybe_foo do
    on input(:foo)

    matches? &is_nil/1 do
      step :do_foo do
        run fn _, _ ->
          {:ok, :noop}
        end
      end
    end
  end
end

Generates the follow error:

** (EXIT from #PID<0.98.0>) an exception was raised:
    ** (KeyError) key :steps not found in: nil

If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
        lib/foo.ex:22: FooReactor.__verify_spark_dsl__/1

Expected behavior The module compiles cleanly without error OR a clearer error on what is missing. EDIT: It seems like default is meant to be optional? At least that's what it looks like from the code

Runtime

Additional context I can try and open a PR with a failing test for this in a bit

ekosz commented 2 weeks ago

This is now fixed with the linked PR merged