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

Function to_float fails to parse "0": Invalid float "0": not a normal f64 number #21970

Closed
PetrHeinz opened this issue Dec 5, 2024 · 2 comments
Labels
meta: regression This issue represents a regression type: bug A code related bug.

Comments

@PetrHeinz
Copy link

A note for the community

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Problem

When using to_float on a zero (either "0", "0.0", "0.000", ...), parsing fails with:

error[E000]: function call error for "to_float" at (142:156): NaN number not supported "Invalid float \"0\": not a normal f64 number"
  ┌─ :4:8
  │
4 │ test = to_float!("0")
  │        ^^^^^^^^^^^^^^ NaN number not supported "Invalid float \"0\": not a normal f64 number"
  │
  = see language documentation at https://vrl.dev
  = try your code in the VRL REPL, learn more at https://vrl.dev/examples

This issue was introduced in newly released 0.43.0.

Configuration

No response

Version

vector 0.43.0 (aarch64-apple-darwin 88e017f 2024-12-03 22:44:54.502541095)

Debug Output

No response

Example Data

    "one": "1",
    "zero": "0",
    "nan": "nan"
}

.zero_float, .zero_float_err = to_float(.zero)
.one_float, .one_float_err = to_float(.one)
.nan_float, .nan_float_err = to_float(.nan)

{
	"nan": "nan",
	"nan_float": 0,
	"nan_float_err": "function call error for \"to_float\" at (120:134): NaN number not supported \"Invalid float \\\"nan\\\": not a normal f64 number\"",
	"one": "1",
	"one_float": 1,
	"one_float_err": null,
	"zero": "0",
	"zero_float": 0,
	"zero_float_err": "function call error for \"to_float\" at (31:46): NaN number not supported \"Invalid float \\\"0\\\": not a normal f64 number\""
}

Additional Context

https://playground.vrl.dev/?state=eyJwcm9ncmFtIjoiLnplcm9fZmxvYXQsIC56ZXJvX2Zsb2F0X2VyciA9IHRvX2Zsb2F0KC56ZXJvKVxuLm9uZV9mbG9hdCwgLm9uZV9mbG9hdF9lcnIgPSB0b19mbG9hdCgub25lKVxuLm5hbl9mbG9hdCwgLm5hbl9mbG9hdF9lcnIgPSB0b19mbG9hdCgubmFuKVxuIiwiZXZlbnQiOnsib25lIjoiMSIsInplcm8iOiIwIiwibmFuIjoibmFuIn0sImlzX2pzb25sIjpmYWxzZSwiZXJyb3IiOm51bGx9

References

vectordotdev/vrl#1107

@PetrHeinz PetrHeinz added the type: bug A code related bug. label Dec 5, 2024
@jszwedko jszwedko added the meta: regression This issue represents a regression label Dec 5, 2024
@pront
Copy link
Member

pront commented Dec 5, 2024

Thanks for the report @PetrHeinz.

As an immediate workaround you can use parse_float, see example.

We will discuss internally about the proper fix, probably checking for is_normal here is too restrictive.

@pront
Copy link
Member

pront commented Dec 9, 2024

Fixed in https://crates.io/crates/vrl/0.20.1

@pront pront closed this as completed Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta: regression This issue represents a regression type: bug A code related bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants