bitwalker / bitwalker/exirc

no function clause matching in String.contains?/2

Open
#77 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Elixir
Stars
154
Forks
38
PR merge metrics
No merged PRs in 30d

Description

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:
```elixir
|> 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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.