apb2006/basex-node — pull request #14 by jesseclark (2014-04-03 00:51:12+00:00)
Title: Fixed no response bug when adding document with invalid xml

When adding/replacing a document containing invalid xml the request would timeout without ever calling the callback method.

In debug mode I could see that the database was returning:
S1<<
'"..." (Line 1): The markup in the document preceding the root element must be well-formed.\u0000\u0001'

This would end up in the else statement in parser2 on line 173 if index.js which would just set the value of self.parser2part without returning a value. This would mean that the parser2 function call would implicitly return undefined which would break out of the while loop in onData (line 106) without ever calling the callback.

This would cause my application hang while waiting for a response and any subsequent calls to the database client to behave unpredictably.

My solution was to return an error response from parser2 with the 'info' field set to 'r.result' so that the callback function would get called from onData with the appropriate parameters.

I added a test case and all tests are passing.

Sorry about reformatting the code a bit. I needed some whitespace in there to read the code more easily.