Leonidas-from-XIV/node-xml2js — pull request #138 by actionshrimp (2014-05-27 10:05:14+00:00)
Title: Don't emit 'error' for excptns caught in 'end' cbs

Currently if the parser 'end' event is used to receive the parsed object and continue execution, there appears to be a bug with the interaction between the 'end' event callback and the parsers 'error' event. If the callback throws for whatever reason, the error event is emitted from the parser (even though parsing has finished). This appears to happen because the try/catch block surrounding @saxParser.write also ends up encompassing all the 'end' event callbacks due to the sync nature of EventEmitter.

The simplest fix seemed to be adding an 'ended' flag which checks if parsing has ended before emitting the error event.