jseutter/ofxparse — pull request #24 by guyrt (2012-03-22 14:44:23+00:00)
Title: Robust error handling

I work at WaveAccounting, a startup in Toronto, ON, and we are using this library. One of our requirements for an ofx file parser is that it be able to recover from some errors and continue to parse the file. This is so we can explain to our users (who are generally not familiar with the OFX file format) why we can't parse ofx file they downloaded from their bank.

I have added this functionality to the ofxparser library in the following way.

The OfxParser class now contains a boolean variable fail_fast. If this is true (the default) then the old behaviour can be expected, except that at times an OfxParserException is raised rather than an IndexError or ValueError.

The statement and investment statement classes contain an extra list called discarded_transactions. Any transactions that can not be parsed are stored here in dictionaries that record the reason for the failure and the content of the error. With the volume of ofx files we receive at Wave, this will let us record what failures are occurring most often so we can fix them.

The statement and investment statement classes contain an extra list called warnings. This records warnings for missing fields and other problems. Again, this is so we can return a more intelligent response to the user than "it broke".

I also added "buystock" and "sellstock" as transaction types in investment accounts.

Tests have been updated to account for the fail_fast behaviour. I also added some tests we were using on an internal version of the library to ensure that dates were handled correctly.

If the ofx file is empty, an exception is raised. This was on your TODO.

Please let me know if you have any questions or if there is anything you would like me to change. If you accept this PR, please add "Richard T Guy" to your authors list.