You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I saw some behaviour that took a moment to figure out why was happening. Turns out I didn't have exponent set up correctly for a custom_currency.
Repro steps:
# Save the below as `repro.exs`# and run it as `elixir repro.exs`Mix.install([{:money,"~> 1.12"}])Application.put_env(:money,:default_currency,:USD)Application.put_env(:money,:custom_currencies,[WILL_WORK: %{name: "WW",symbol: "WW$",exponent: 2},WILL_CRY: %{name: "WC",symbol: ":("}])ExUnit.start()defmoduleTestdouseExUnit.Casedescribe"exponent needs to be present"dotest"cries down the road when we dont set exponent"do# Everything passesassert%Money{amount: 123,currency: :USD}=usd=Money.new(123)assert%Money{amount: 123,currency: :WILL_WORK}=will_work=Money.new(123,:WILL_WORK)assert%Money{amount: 123,currency: :WILL_CRY}=will_cry=Money.new(123,:WILL_CRY)assert"$1.23"=Money.to_string(usd)assert"WW$1.23"=Money.to_string(will_work)# This one doesn't passassert:will_cry=Money.to_string(will_cry)endendend
Here is the error:
1) test exponent needs to be present cries down the road when we dont set exponent (Test)
repro.exs:21
** (ArithmeticError) bad argument in arithmetic expression: nil + 1
code: assert :will_cry = Money.to_string(will_cry)
stacktrace:
:erlang.+(nil, 1)
(money 1.12.4) lib/money.ex:716: Money.format_number/2
(money 1.12.4) lib/money.ex:612: Money.to_string/2
repro.exs:31: (test)
Expected behaviour
Get an error message directing me to the required config, like we have for normal currencies.
Potential solution
Should we verify/raise if the custom_currencies don't have all the required
config for the normal/expected usage? Similar to what happens with not having a
default currency.
I don't know what else breaks without the required custom_currencies config.
This was the only instance I observed but I also haven't done much more with
it.
Hope this helps start a conversation. Thanks again for the lib! ❤️
The text was updated successfully, but these errors were encountered:
Hi! Thanks for the lib!
I saw some behaviour that took a moment to figure out why was happening. Turns out I didn't have
exponent
set up correctly for acustom_currency
.Repro steps:
Here is the error:
Expected behaviour
Get an error message directing me to the required config, like we have for normal currencies.
Potential solution
Should we verify/raise if the
custom_currencies
don't have all the requiredconfig for the normal/expected usage? Similar to what happens with not having a
default currency.
I don't know what else breaks without the required
custom_currencies
config.This was the only instance I observed but I also haven't done much more with
it.
Hope this helps start a conversation. Thanks again for the lib! ❤️
The text was updated successfully, but these errors were encountered: