Here's an example:
defmodule Example do
def run() do
Demo.handle_in("UNEXPECTED", "foo", "bar")
end
def handle_in("click", map, socket) do
IO.puts("whatever")
end
end
And here's the error message when we call run/0:
iex(1)> Example.run
** (FunctionClauseError) no function clause matching in Example.handle_in/3
The following arguments were given to Example.handle_in/3:
# 1
"UNEXPECTED"
# 2
"foo"
# 3
"bar"
You can see from this output, that run/1 calls handle_in/3 with "UNEXPECTED" as its first argument. There is no clause of handle_in that expects that, so elixir generates the error. A common way to handle this if you can't control the inputs is to add a catch-all clause that does not pattern-match the arguments:
def handle_in("click", map, socket) do
IO.puts("clicked")
end
def handle_in(one, two, three) do
IO.puts("Called with: #{inspect one}, #{inspect two}, #{inspect three}")
end
Now the error is not produced, because the second clause can handle the "UNEXPECTED" string:
iex(1)> Example.run
Called with: "UNEXPECTED", "foo", "bar"
:ok
In your case, it could be that the "click" string is not passed, or that the 2nd argument isn't a map that contains the "click" key, but without the calling code or error message, it's impossible to tell.
handle_in/3is getting called with different arguments. Are you handling the general case there? - Brett Beattyclickfunction, because you're passing 2 arguments in every call that's shown. But it could be inhandle_inif it's being called with something other than"click"or a map that doesn't contain the"click"key. - sbacarobhandle_in, but by the code that calls handle in. I edited your question to remove the unrelated information. Please post the full errror message and the code that callshandle_in. - Adam Millerchipdef handle_in("click", payload, socket), do: IO.puts(payload)` - Vasu Adari