RubyMoney / monetize

A library for converting various objects into `Money` objects.
MIT License
430 stars 107 forks source link

#parse does not rescue all errors #166

Closed shamas- closed 8 months ago

shamas- commented 1 year ago

Repro steps:

Monetize.parse(1+3i)

Expected:

=> nil

Actual:

ArgumentError: Unable to make a BigDecimal from non-zero imaginary number

Using Ruby 3.0.6.

It might be because Error inherits from StandardError https://github.com/RubyMoney/monetize/blob/e2e2f1f2dbc8e599797f7582dc389bdde9ac6999/lib/monetize/errors.rb#L2

and is used here https://github.com/RubyMoney/monetize/blob/e2e2f1f2dbc8e599797f7582dc389bdde9ac6999/lib/monetize.rb#L29-L33

If I do

begin
  Monetize.parse(1+3i)
rescue StandardError
  pp 'hi there'
end

the error is rescued.

semmons99 commented 8 months ago

please submit a PR for consideration