Skip to content

Improve Router Registration Error#644

Open
TylerPachal wants to merge 3 commits intocommanded:masterfrom
TylerPachal:improve-router-dispatch-error
Open

Improve Router Registration Error#644
TylerPachal wants to merge 3 commits intocommanded:masterfrom
TylerPachal:improve-router-dispatch-error

Conversation

@TylerPachal
Copy link
Contributor

@TylerPachal TylerPachal commented Feb 4, 2026

If you forgot to include the required :to option in dispatch(...) during your router registration you would get an unhelpful error (as noted in #422). This PR fixes that, so that a more helpful error is returned.

Additionally, while trying to replicate this I found another bug with the registration arguments: if the :to option was not the first option in the list, things would break. I've addressed that bug here as well because it was in the same part of the code.

For this PR, the first commit was adding the new tests (which failed), and the second commit is the changes to get the tests passing.

Closes #422

Comment on lines -669 to -670
defp parse_opts([{:to, aggregate_or_handler} | opts], result) do
case Keyword.pop(opts, :aggregate) do
Copy link
Contributor Author

@TylerPachal TylerPachal Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation: This was problematic. This assume that the :to was always before the :aggregate, and would break when that was not the case. There was also a funny interaction with the :function option because of how it was set to either :execute or :handle (so again, depending on order, you could lose a user-provide value for :function).

The fix is to pull out the options we need so they can be compared together, instead of looping over them sequentially.

Comment on lines +681 to +683
case {to, aggregate} do
{nil, _aggregate} ->
raise "dispatch missing required parameter: :to"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation: The raise is the actual improvement to #644. See the unit test for an example.

@TylerPachal TylerPachal marked this pull request as ready for review February 4, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dispatch without :to option gives an unexpected error message

1 participant