Details
-
Bug
-
Resolution: Fixed
-
Major
-
2.4.5
-
None
-
1
Description
When a view error occurs, we try to parse the error that we get back from the view engine at https://github.com/couchbase/couchnode/blob/a3a240a2cf0d93e79a4051c33bce74094ca97cca/lib/bucket.js#L613.
The problem is that the logic isn't quite complete here.
var errStr = val; |
var jsonError = JSON.parse(errStr); |
var errorMessage = 'unknown error : error parsing failed'; |
if (jsonError) { |
errorMessage = jsonError.message;
|
if (jsonError.error || jsonError.reason) { |
var subError = jsonError.error + ': ' + jsonError.reason; |
if (!errorMessage) { |
errorMessage = subError;
|
} else { |
errorMessage += ' (' + subError + ')'; |
}
|
}
|
}
|
|
var err = new Error(errorMessage); |
err.responseBody = errStr;
|
emitter.emit('error', err); |
I think the overall logic is 'try to parse the json error, if that fails then just use the string', but we don't actually have any error handling around the json parsing.
That means if you receive something that (for example) is truncated, the JSON.parse() will error out, but as we do not catch the error we never reach the rest of the logic.
Even worse still it causes the application running the view query to crash.
I am not sure exactly what causes invalid json to be passed through from the view engine, but given this occurs in a failure scenario, we should protect the SDK from crashes wherever possible.
Attachments
For Gerrit Dashboard: JSCBC-461 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
93212,2 | JSCBC-461: Handle view error parsing errors. | master | couchnode | Status: MERGED | +2 | +1 |
93216,2 | JSCBC-461: Handle view error parsing errors. | v2.4 | couchnode | Status: MERGED | +2 | +1 |