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

Dialyzer fails when using escape_max_lines option #120

Closed
hidnasio opened this issue Nov 18, 2022 · 1 comment
Closed

Dialyzer fails when using escape_max_lines option #120

hidnasio opened this issue Nov 18, 2022 · 1 comment

Comments

@hidnasio
Copy link

Hi, thank you for this awesome library!

I run into an issue with Dialyzer when using the option escape_max_lines because the spec doesn't define it as an option, even though the error mention it as one.

** (CSV.EscapeSequenceError) Escape sequence started on line 145:

"... a lot of text here ..."

did not terminate. You can use normal mode to continue parsing rows even if single rows have errors.

Escape sequences are allowed to span up to 10 lines. This threshold avoids collecting the whole file into memory when an escape sequence does not terminate.
You can change it using the escape_max_lines option: https://hexdocs.pm/csv/CSV.html#decode/2

    (csv 3.0.3) lib/csv.ex:256: CSV.yield_or_raise!/2

Using escape_max_lines as the error mentions causes Dialyzer to throw the error

path/to/file:no_return Function function_name/1 has no local return.

missing in the spec here

If this is a bug, steps to reproduce it

Writing a function like the following and running Dialyzer

  def my_fun(stream) do
    CSV.decode!(stream, escape_max_lines: 11)
  end

The option can be tested like

test "raises error for escape sequences spanning more than 10 lines" do
  stream = ["\"a\na\na\na\na\na\na\na\na\na\na\na\n"] |> to_stream

  assert_raise CSV.EscapeSequenceError, fn ->
    CSV.decode!(stream) |> Stream.run()
  end

  result = CSV.decode!(stream, escape_max_lines: 11) |> Enum.to_list()
  assert [["a\na\na\na\na\na\na\na\na\na\na\n"]] == result
end

I can open a PR to add the missing option to the spec and docs if needed

@beatrichartz
Copy link
Owner

Thanks for raising this, added this to the typespecs and released it in 3.0.4

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

2 participants