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

no function clause matching in String.contains?/2 #77

Open
mjaneczek opened this issue Dec 29, 2017 · 0 comments
Open

no function clause matching in String.contains?/2 #77

mjaneczek opened this issue Dec 29, 2017 · 0 comments

Comments

@mjaneczek
Copy link

Hello!

The error:

** (FunctionClauseError) no function clause matching in String.contains?/2
    (elixir) lib/string.ex:1767: String.contains?({:incomplete, "⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐", <<226>>}, "example")
    (exirc) lib/exirc/client.ex:721: ExIrc.Client.handle_data/2
    (stdlib) gen_server.erl:601: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:667: :gen_server.handle_msg/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

I have investigated it a little bit and think that the problem is here:

|> Enum.map(fn(s) ->
  case String.valid?(s) do
    true -> :unicode.characters_to_binary(s)
    false -> :unicode.characters_to_binary(s, :latin1, :unicode)
  end
end)

https://github.com/bitwalker/exirc/blob/master/lib/exirc/utils.ex#L81

From the erlang doc:

characters_to_binary

Result = 
    binary() |
    {error, binary(), RestData} |
    {incomplete, binary(), binary()}

http://erlang.org/doc/man/unicode.html#characters_to_binary-1

So basically we need to handle the situation when the string is incomplete, maybe a fallback to empty string would be enough?

I'm not sure about the proper solution, any ideas?

Thank you!

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

1 participant