Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid quoted expression: %{} #69

Open
FabienHenon opened this issue Jun 21, 2024 · 2 comments
Open

invalid quoted expression: %{} #69

FabienHenon opened this issue Jun 21, 2024 · 2 comments

Comments

@FabienHenon
Copy link

FabienHenon commented Jun 21, 2024

Hi,

I'm trying to compile my first project with WalEx. So I created a small project to test the lib and I got the following compilation error: invalid quoted expression: %{}

I used this code :

defmodule MyOwnApp.Events.Users do
  use WalEx.Event, name: MyOwnApp

  # any subscribed event
  on_event(:all, fn events ->
    IO.inspect(events: events)
  end)

  # any user event
  on_event(:users, fn users ->
    IO.inspect(on_event: users)
    # do something with users data
  end)

  # any user insert event
  on_insert(:users, fn users ->
    IO.inspect(on_insert: users)
  end)

  on_update(:users, fn users ->
    IO.inspect(on_update: users)
  end)

  on_delete(:users, fn users ->
    IO.inspect(on_delete: users)
  end)
end

And I'm using the version 4 of WalEx.

Any idea? I'm a bit rusted with Elixir macros 😅

@cpursley
Copy link
Owner

I missed this message @FabienHenon - were you able to figure the issue out? If not, can you describe it in more detail with logs if possible? Merci.

@FabienHenon
Copy link
Author

Hi,

Yes I was able to fix the issue.

It was because I was using the default value of the filters parameter (of the on_event macro), which is %{}. This value, when in the macro, is still %{} and cannot be unquoted (This is the exception I got).

I tried to escape it with Macro.escape before unquoting it and it worked, but then it stopped working when I passed a value to the filters parameter of the macro (not using the default value).
In this case, the unquoted value of the parameter was {:%{}, [], []}, which was not correct.

I don't know how to make defautl parameter value and explicit value work at the same time with macros.

So I didn't change the code and put %{} explicitly as value for the filters parameter of the on_event macro. It works like that (but not if I use the default value)

I also noticed another issue, with the replication slot this time.
When I do not manually set the slot_name config parameter, one is generated.
But the generated name uses forbidden characters (like dot '.').
Thus the query fails.

To solve this issue I explicitly set the slot_name config parameter value myself.

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

No branches or pull requests

2 participants