Closed
Description
I was surprised to learn today that this works:
iex > Money.new(:USD, "NaN")
Money.new(:USD, "NaN")
I would sort of have expected an error similar to:
iex > Money.new(:USD, "greg")
{:error,
{Money.InvalidAmountError, "Amount cannot be converted to a number: \"greg\""}}
We have some legacy data floating around that, it turns out have been persisting these due to bad data. We then tried to call Money.to_integer_exp(money)
on one of them and that raises:
(We are on Money 5.10.0
at the moment so the stack trace doesn't line up w/ master)
ArithmeticError: bad argument in arithmetic expression
Module "erlang", in :erlang.*/2
File "lib/money.ex", line 1947, in Money.to_integer_exp/2
Curious your thoughts on this; we can figure out a work around on our end pretty easily so we aren't blocked here.
Thanks, again, for everything you do!
Metadata
Metadata
Assignees
Labels
No labels
Activity
LostKobrakai commentedon Oct 12, 2022
This is probably a sideeffect of the underlying
Decimal
library, which supports:NaN
as well as:inf
. Not sure if that's an intended sideeffect or not though.kipcole9 commentedon Oct 12, 2022
@coladarci thanks for the report and definitely a bug (arises for the reasons @LostKobrakai noted). I have published ex_money version 5.12.2 with the following changelog entry:
Bug Fixes
Don't create NaN or Inf money structs. Closes kipcole9#143