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

Argument error when calling Float.parse #6

Closed
joshuap opened this issue Oct 13, 2015 · 2 comments
Closed

Argument error when calling Float.parse #6

joshuap opened this issue Oct 13, 2015 · 2 comments

Comments

@joshuap
Copy link

joshuap commented Oct 13, 2015

We've been having the following error when parsing certain log entries:

17:13:19.057 [error] Task #PID<0.12050.1556> started from #PID<0.15023.1556> terminating
** (ArgumentError) argument error
    :erlang.binary_to_float("358.0e5437")
    (elixir) lib/float.ex:67: Float.parse_unsigned/4
    (logfmt) lib/decoder.ex:146: Logfmt.Decoder.coerce_value/1
    (logfmt) lib/decoder.ex:129: Logfmt.Decoder.put_value/3
    (logfmt) lib/decoder.ex:84: Logfmt.Decoder.parse_char/5
    (my_app) lib/my_app/parser.ex:27: MyApp.Parser.parse_match/1
    (elixir) lib/stream.ex:454: anonymous fn/4 in Stream.map/2
    (elixir) lib/enum.ex:2607: Enumerable.List.reduce/3
Function: #Function<4.74185808/0 in MyApp.Router.process/2>
    Args: []

=CRASH REPORT==== 12-Oct-2015::17:13:19 ===
  crasher:
    initial call: Elixir.MyApp.Router:-process/2-fun-0-/0
    pid: <0.12050.1556>
    registered_name: []
    exception exit: {badarg,
                        [{erlang,binary_to_float,[<<"358.0e5437">>],[]},
                         {'Elixir.Float',parse_unsigned,4,
                             [{file,"lib/float.ex"},{line,67}]},
                         {'Elixir.Logfmt.Decoder',coerce_value,1,
                             [{file,"lib/decoder.ex"},{line,146}]},
                         {'Elixir.Logfmt.Decoder',put_value,3,
                             [{file,"lib/decoder.ex"},{line,129}]},
                         {'Elixir.Logfmt.Decoder',parse_char,5,
                             [{file,"lib/decoder.ex"},{line,84}]},
                         {'Elixir.MyApp.Parser',parse_match,1,
                             [{file,"lib/my_app/parser.ex"},{line,27}]},
                         {'Elixir.Stream','-map/2-fun-0-',4,
                             [{file,"lib/stream.ex"},{line,454}]},
                         {'Elixir.Enumerable.List',reduce,3,
                             [{file,"lib/enum.ex"},{line,2607}]}]}
      in function  'Elixir.Task.Supervised':exit/4 (lib/task/supervised.ex, line 105)
    ancestors: [<0.15023.1556>]
    messages: []
    links: []
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 987
    stack_size: 27
    reductions: 1059
  neighbours:

The issue appears to be in Decoder.coerce_value/1:

https://github.com/jclem/logfmt-elixir/blob/master/lib/decoder.ex#L146

To reproduce the error, try calling Float.parse("358.0e5437") from iex. Could this be a bug in Elixir's implementation of Float.parse/1? I would expect exceptions to be caught and :error returned per the documentation.

@joshuap
Copy link
Author

joshuap commented Oct 13, 2015

After discussing this error on elixir-lang/elixir#3862 I updated the documentation for Float.parse/1; the ArgumentError can be expected for the time being. I think the solution is to rescue those errors when parsing floats; I'll put together a PR for that if you want me to @jclem.

@jclem
Copy link
Owner

jclem commented Oct 13, 2015

A PR would be great! Not to get into an unrelated discussion on here, but I'm considering removing the value parsing altogether in a future version, and leaving that up to the user.

On Oct 13, 2015, at 12:05 PM, joshuap notifications@github.com wrote:

After discussing this error on elixir-lang/elixir#3862 I updated the documentation for Float.parse/1; the ArgumentError can be expected for the time being. I think the solution is to rescue those errors when parsing floats; I'll put together a PR for that if you want me to @jclem.


Reply to this email directly or view it on GitHub.

@jclem jclem closed this as completed in 9bc17ea Mar 20, 2016
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