viafintech / camt_parser

A basic parser for camt.052, camt.053 and camt.054 files
MIT License
20 stars 24 forks source link

ArgumentError: invalid value for BigDecimal(): "" #21

Closed moiristo closed 5 years ago

moiristo commented 5 years ago

Hi,

Somehow a client of us managed to get hold of a CAMT file with transactions without an amount. This yields the error described with the trace below. As this is not easy to catch, I think the gem should check the value before building the BigDecimal. Maybe a validation? I'm using amount_in_cents now, as this yields zero when no amount is set.

[GEM_ROOT]/gems/camt_parser-2.4.0/lib/camt_parser/misc.rb:9 :in `BigDecimal`
[GEM_ROOT]/gems/camt_parser-2.4.0/lib/camt_parser/misc.rb:9 :in `to_amount`
[GEM_ROOT]/gems/camt_parser-2.4.0/lib/camt_parser/general/transaction.rb:11 :in `amount`
tobischo commented 5 years ago

Hmm, yeah, unfortunately way too many fields in camt files are actually optional.

What would your expectation be in terms of behaviour? I could imagine both: a better exception or defaulting to 0, which is technically correct for something that has no amount.

Could you provide us with a little bit of background on the reason for that transaction not having an amount? What kind of transaction is it?

moiristo commented 5 years ago

I wish I knew, but unfortunately I can't see what the user has uploaded. However, I'd say that the most logical behaviour would be that amount_in_cents and amount both yield nil when no value is set, as no amount has been passed?

tobischo commented 5 years ago

Yeah, that's true. We will adapt it accordingly

tobischo commented 5 years ago

Resolved in #22 and released as v2.6.1

moiristo commented 5 years ago

Thanks!