# Phoenix Counting Application - (FunctionClauseError) no function clause matching

**URL:** <https://forum.elixirforum.com/t/phoenix-counting-application-functionclauseerror-no-function-clause-matching/46413>\
**Category:** Questions\
**Tags:** phoenix\
**Created:** [March 6, 2022, 7:35pm UTC](https://forum.elixirforum.com/t/phoenix-counting-application-functionclauseerror-no-function-clause-matching/46413 "2022-03-06T19:35:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![spizzy](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@spizzy](https://forum.elixirforum.com/u/spizzy)\
**Post date:** [March 6, 2022, 7:35pm UTC](https://forum.elixirforum.com/t/phoenix-counting-application-functionclauseerror-no-function-clause-matching/46413/1 "2022-03-06T19:35:02Z")

</div>

I’m currently learning some phoenix and built a counting app with a simple increase/decrease. Both worked fine so I decided to implement GenServers and PubSub to see how many users currently are on the page (presence).

Whole error:

```elixir
GenServer #PID<0.511.0> terminating
** (FunctionClauseError) no function clause matching in CounterWeb.Counter.handle_info/2
    (counter 0.1.0) lib/counter_web/live/counter.ex:45: CounterWeb.Counter.handle_info({:count, 1}, #Phoenix.LiveView.Socket<assigns: %{ __changed__ : %{}, flash: %{}, live_action: nil, present: 1, val: 
1}, endpoint: CounterWeb.Endpoint, id: "phx-FtSq5dehn8AlGgAF", parent_pid: nil, root_pid: #PID<0.511.0>, router: CounterWeb.Router, transport_pid: #PID<0.506.0>, view: CounterWeb.Counter, ...>)  

```

I think it’s coming from my make change function

```elixir
defp make_change(count, change) do
    new_count = count + change
    PubSub.broadcast(Counter.PubSub, topic(), {:count, new_count})
    {:reply, new_count, new_count}
  end

```

and my handle info

```elixir
def handle_info(
       %{event: "presence_diff", payload: %{joins: joins, leaves: leaves}},
       %{assigns: %{present: present}} = socket
    ) do
   new_present = present + map_size(joins) - map_size(leaves)

   {:noreply, assign(socket, :present, new_present)}
end

```

Someone recommended me to create another clause and do the same kind of setup as I did with the previous functions to handle the calls, example:

```elixir
def handle_call(:reply, _from, count) do
    {:ok, count, count}
  end

  def handle_call(:incr, _from, count) do
    make_change(count, +1)
  end

  def handle_call(:decr, _from, count) do
    make_change(count, -1)
  end

```

My first argument is the message I receive, I am sending a tuple and I have to match that tuple.

I think I have to add another handle\_info, like this

```elixir
def handle_info({count: count}, socket) do
   # ???
   {:noreply, socket}
end

```

How would I handle/implement that? Can anyone help me by explaining that a bit?

---

<div class="post-metadata">

**Author:** ![kartheek](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kartheek/32/19143_2.png) [@kartheek](https://forum.elixirforum.com/u/kartheek)\
**Post date:** [March 7, 2022, 4:15am UTC](https://forum.elixirforum.com/t/phoenix-counting-application-functionclauseerror-no-function-clause-matching/46413/2 "2022-03-07T04:15:39Z")

</div>

If you are getting function clause matching error - you have to add new handle\_info/2

It should be like what is described in error message `{:count, count}` not `{count: count}`

> [@spizzy](#):
>
> `handle_info({:count, 1},`

```elixir
def handle_info({:count, count}, socket) do
...

```

I am little confused - you are speaking about GenServer and the error message and your sample code refers to PhoenixLiveView.Socket.

You have implemented the GenServer and Pubsub part and you want to handle the PubSub message in LiveView ?

---

<div class="post-metadata">

**Author:** ![spizzy](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@spizzy](https://forum.elixirforum.com/u/spizzy)\
**Post date:** [March 11, 2022, 4:26pm UTC](https://forum.elixirforum.com/t/phoenix-counting-application-functionclauseerror-no-function-clause-matching/46413/3 "2022-03-11T16:26:21Z")

</div>

so just

```elixir
def handle_info({:count, count}, socket) do
    {:noreply, assign(socket, val: count)}
  end

```

---

<div class="post-metadata">

**Author:** ![kartheek](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kartheek/32/19143_2.png) [@kartheek](https://forum.elixirforum.com/u/kartheek)\
**Post date:** [March 12, 2022, 1:48pm UTC](https://forum.elixirforum.com/t/phoenix-counting-application-functionclauseerror-no-function-clause-matching/46413/4 "2022-03-12T13:48:33Z")

</div>

> [@spizzy](#):
>
> `{:noreply, assign(socket, val: count)}`

`{:noreply, assign(socket, :val, count)}` - did it work ?

---

<div class="post-metadata">

**Author:** ![spizzy](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@spizzy](https://forum.elixirforum.com/u/spizzy)\
**Post date:** [March 15, 2022, 8:26pm UTC](https://forum.elixirforum.com/t/phoenix-counting-application-functionclauseerror-no-function-clause-matching/46413/5 "2022-03-15T20:26:23Z")

</div>

I just had to add the following function to get it working, is there any better solution maybe?

```elixir
def handle_info({:count, count}, socket) do
    {:noreply, assign(socket, val: count)}
  end

```
