Skip to content

Silently throws away data from the response if it contains UTF-8 characters #93

@StephenWeatherford

Description

@StephenWeatherford

When reading data from an Azure CosmosDB graph, where the data contains non-ansi characters, e.g.:

{
"type": "vertex",
"properties": {
"text": [
{
"id": "a0a0eb9e-8679-4c80-a0e4-ea2e00a96b71",
"value": "RT @colisscom: [JS]このスクリプト一つで、さまざまな用途に合わせたスライダーが実装できて便利 -Tiny Slider\n\nhttps://t.co/ObL6zbEAN4 https://t.co/J0KtrMAgor"
}
],
...

I'm seeing a lot of the data getting silently lost. The problem occurs here in GremlinClient.js:

handleProtocolMessage(message) {
let rawMessage, requestId, statusCode, statusMessage;
try {
const { data } = message;
const buffer = new Buffer(data, 'binary'); <<<< message.data is a string, and message.binary = false
rawMessage = JSON.parse(buffer.toString('utf-8'));
requestId = rawMessage.requestId;
statusCode = rawMessage.status.code;
statusMessage = rawMessage.status.message;
} catch (e) {
this.warn('MalformedResponse', 'Received malformed response message'); <<<< HITS HERE
return;
}

In this case the message is already a UTF-decoded string (message.binary = false). Also, wouldn't it be better to bubble up the exception, rather than silently cutting it off?

Seems like the code should be something like:

  const { data } = message;
  if (message.binary) {
      const buffer = new Buffer(data, 'binary');
      rawMessage = JSON.parse(buffer.toString('utf-8'));
   } else {
      rawMessage = data;
   }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions