Phoenix_live_view: no function clause matching in Phoenix.LiveView.Channel.gather_keys/2

Created on 29 Oct 2020  路  6Comments  路  Source: phoenixframework/phoenix_live_view

Overview

gather_keys/2 can't handle an empty string as the first parameter.

Example Repo

https://github.com/molenick/gather_keys_issue

Environment

  • Elixir version (elixir -v): 1.10.4 (compiled with Erlang/OTP 22)
  • Phoenix version (mix deps): 1.5.6 (and 1.5.4)
  • Phoenix LiveView version (mix deps): 0.14.7 (and 0.13.0)
  • NodeJS version (node -v): v12.16.1
  • NPM version (npm -v): 6.13.4
  • Operating system: OSX 10.15.7 (Catalina)
  • Browsers you attempted to reproduce this bug on (the more the merrier): Chrome
  • Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: Yes

Actual behavior

Similar to https://github.com/phoenixframework/phoenix_live_view/pull/336, I'm getting an error (FunctionClauseError) no function clause matching in Phoenix.LiveView.Channel.gather_keys/2 when trying to add a new resources using the live view.

I created a new project with:
mix phx.new my_app --live --database=postgres
I generated a resource like this:
mix phx.gen.live Resources Resource resource description:string

When I go to localhost:4000/resources and click "New Resource" the modal shows as is expect.
When I begin typing in the description text field, the app seems to hang and in my phx.server console is the following:

13:26:49.100 [error] GenServer #PID<0.575.0> terminating
** (FunctionClauseError) no function clause matching in Phoenix.LiveView.Channel.gather_keys/2
    (phoenix_live_view 0.14.7) lib/phoenix_live_view/channel.ex:425: Phoenix.LiveView.Channel.gather_keys("", ["description", "resource"])
    (phoenix_live_view 0.14.7) lib/phoenix_live_view/channel.ex:419: Phoenix.LiveView.Channel.decode_merge_target/1
    (phoenix_live_view 0.14.7) lib/phoenix_live_view/channel.ex:102: Phoenix.LiveView.Channel.handle_info/2
    (stdlib 3.12.1) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib 3.12.1) gen_server.erl:711: :gen_server.handle_msg/6
    (stdlib 3.12.1) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: %Phoenix.Socket.Message{event: "event", join_ref: "4", payload: %{"cid" => 2, "event" => "validate", "type" => "form", "value" => "_csrf_token=ABCDEF&resource%5Bdescription%5D=w&_target=resource%5Bdescription%5D"}, ref: "6", topic: "lv:phx-FEDCBA"}

Seeing that the function was trying to match on empty string and acc, I went and added a new gather_keys/2 like so:

  defp gather_keys("", acc), do: acc

...and things were good again! I was a bit baffled because I had recently built another project very similarly and didn't encounter this.

Expected behavior

I should be able to add a new resource successfully.

Most helpful comment

Actually, it is a LiveView issue, I just wanted to say it is tracked inPlug too. The fix for LV is already In master, we just Need a new release.

All 6 comments

It is a Plug issue: https://github.com/elixir-plug/plug/issues/994 :)

It is a Plug issue: elixir-plug/plug#994 :)

Ah, thanks. I went to make a pull request for this, but saw that

defp gather_keys(nil, acc), do: acc
has been replaced with
defp gather_keys(_, acc), do: acc

in the latest source, which seems like it may fix my issue. My other option is to remove validate from the components change event, which I don't really need for my use case.

Actually, it is a LiveView issue, I just wanted to say it is tracked inPlug too. The fix for LV is already In master, we just Need a new release.

Awesome, thanks! I pinned the Plug version like you recommended and that's letting me move forward for now. :)

I ran into the same problem today. Waiting for the next release :blush:

Closed via v0.14.8

Was this page helpful?
0 / 5 - 0 ratings