Hey OGs,
I have a function that loads csv files into my app. When my user used special characters, it failed
they used name like: Zoë
Here is my function:
defp read(csv) do
csv.path
|> Path.expand()
|> File.stream!()
|> CSV.decode(headers: true)
|> Stream.map(fn {:ok, data} -> data end)
|> Stream.reject(&is_nil/1)
|> break_point()
|> Enum.to_list() # It fails here
|> Enum.uniq()
end
Error:
The following arguments were given to CSV.Decoding.Preprocessing.Lines.starts_sequence?/5:
# 1
<<145, 32, 72, 111, 97, 100, 44, 105, 110, 115, 116, 97, 103, 114, 97, 109>>
# 2
"o"
# 3
false
# 4
44
# 5
""
Attempted function clauses (showing 5 out of 5):
defp starts_sequence?(<<34::utf8(), tail::binary()>>, last_token, false, separator, _) when last_token == <<separator::utf8()>>
defp starts_sequence?(<<34::utf8(), tail::binary()>>, "", false, separator, _)
defp starts_sequence?(<<34::utf8(), tail::binary()>>, _, quoted, separator, sequence_start)
defp starts_sequence?(<<head::utf8(), tail::binary()>>, _, quoted, separator, sequence_start)
defp starts_sequence?("", _, quoted, _, sequence_start)
Apparently, it couldn’t recognise this character ë
I wished I could like make a callback for starts_sequence? to return a meaningful error or something like that…
How can I prevent this from happening ?