gremlin-javascript icon indicating copy to clipboard operation
gremlin-javascript copied to clipboard

Error: Expected Stream, got object

Open godronus opened this issue 6 years ago • 13 comments

Trying to connect to either a Janus database, Tinkergraph Database or OreintDB. In each case I have managed to connect a gremlin server to the database. I am able to connect to the gremlin server with the gremlin console and can traverse the records. However I am unable to do so with gremlin-javascript. If you could add some insight to what I am doing wrong it would be muchly appreciated. simple code I am using:

var gremlin = require('gremlin');
var client = gremlin.createClient();
console.log(client);
var script = 'g.V()';
// Callback style
client.execute(script, function(err, res) {
   console.log(err, res);
});

the error stack: (Including the console.log of the client):

client GremlinClient {
   domain: null,
   _events: {},
   _eventsCount: 0,
   _maxListeners: undefined,
   port: 8182,
   host: 'localhost',
   options:
    { language: 'gremlin-groovy',
      session: false,
      op: 'eval',
      processor: '',
      accept: 'application/json',
      executeHandler: [Function: defaultExecuteHandler],
      ssl: false,
      rejectUnauthorized: true,
      user: '',
      password: '',
      path: '/gremlin' },
   useSession: false,
   user: '',
   password: '',
   connected: false,
   queue: [],
   commands: {},
   connection:
    WebSocketGremlinConnection {
      domain: null,
      _events:
       { open: [Function],
         error: [Function],
         message: [Function],
         close: [Function] },
      _eventsCount: 4,
      _maxListeners: undefined,
      open: false,
      ws:
       WebSocket {
         domain: null,
         _events: [Object],
         _eventsCount: 4,
         _maxListeners: undefined,
         readyState: 0,
         bytesReceived: 0,
         extensions: {},
         protocol: '',
         _binaryType: 'arraybuffer',
         _finalize: [Function: bound finalize],
         _finalizeCalled: false,
         _closeMessage: null,
         _closeTimer: null,
         _closeCode: null,
         _receiver: null,
         _sender: null,
         _socket: null,
         _ultron: null,
         protocolVersion: 13,
         _isServer: false,
         url: 'ws://localhost:8182/gremlin',
         _req: [Object] } } }
events.js:182
       throw er; // Unhandled 'error' event
       ^

Error: Expected Stream, got object
     at
/home/farqs/Code/testClient/node_modules/highland/lib/index.js:3504:26
     at
/home/farqs/Code/testClient/node_modules/highland/lib/index.js:1576:9
     at Stream.s._send
(/home/farqs/Code/testClient/node_modules/highland/lib/index.js:1532:9)
     at Stream.write
(/home/farqs/Code/testClient/node_modules/highland/lib/index.js:1633:18)
     at Stream._send
(/home/farqs/Code/testClient/node_modules/highland/lib/index.js:959:26)
     at push
(/home/farqs/Code/testClient/node_modules/highland/lib/index.js:1498:19)
     at
/home/farqs/Code/testClient/node_modules/highland/lib/index.js:2104:13
     at Stream.s._send
(/home/farqs/Code/testClient/node_modules/highland/lib/index.js:1532:9)
     at Stream.write
(/home/farqs/Code/testClient/node_modules/highland/lib/index.js:1633:18)
     at Stream._send
(/home/farqs/Code/testClient/node_modules/highland/lib/index.js:959:26)

godronus avatar Nov 02 '17 14:11 godronus

Are you positive the server you're connecting to is up and running?

jbmusso avatar Nov 09 '17 15:11 jbmusso

Sorry, my mistake.. Server was not up and running properly. Thanks for the assistance

godronus avatar Nov 09 '17 22:11 godronus

Glad I could help. Maybe we should make that error more clear.

jbmusso avatar Nov 10 '17 09:11 jbmusso

I am coming across the same error. My server is running and returning a response.

var gremlin = require('gremlin'); 

const client = gremlin.createClient(8182);

var script = 'g.V()';

client.execute(script, function(err, res) {
  console.log(err, res);
});

The server returns an object and somewhere deep down in the call stack the stream library throws an error because it does not expect this object.

Edit: Using Tinkerpop Gremlin Server 3.3.0

Tomen avatar Dec 16 '17 16:12 Tomen

Tomen, I am having the same error as you. My tinkerpop is 3.3.0 as well. I am able to connect with the java-based gremlin console, but get the same error as you from Node.js. I have a lot of tracing on in the gremlin-server and I can see that the expression "g.V()" is received and it at least begins to evaluate.

My vesion of Node.js v6.11.1

Did you figure it out?

JoeNemo avatar Dec 17 '17 22:12 JoeNemo

jbmusso, I was wondering if the serialization is always GraphSON, or does this do Gryo, or both, selectably? Thanks.

JoeNemo avatar Dec 18 '17 06:12 JoeNemo

I spent about 3 hours trying to figure out what is going on. I might be able to post some intermediary results tonight. I think it has to be something simple, like a configuration issue, since this is concerning basic app functionality.

I was also thinking that it might have to do with the server response format or that the issue relates to some version incompatibility.

/ping @JoeNemo

Tomen avatar Dec 18 '17 06:12 Tomen

@JoeNemo The serialization is always GraphSON but this could be made configurable with some work. I didn't experienced that but this "Error: Expected Stream, got object" issue has been poping here and there for other users. @Tomen would you mind sharing your results on that? I'm not fond of using that internal stream library and I think this should be ditched in favor of something else (maybe RxJS/Observable).

jbmusso avatar Dec 18 '17 14:12 jbmusso

At the end of this comment I will post the complete call stack to the error.

So assume you have some vertices or anything that returns an actual result and does not go over to 204 No Content.

  1. So GremlinClient sends the message.
  2. handleProtocolMessage() gets called. We switch(statusCode) in line 163, go into case 200 and push the raw message in line 167
      switch (statusCode) {
        case 200:
          // SUCCESS
          delete this.commands[requestId]; // TODO: optimize performance
          messageStream.push(rawMessage);
          messageStream.push(null);
          break;

By now, the rawMessage object looks like this: https://gist.github.com/Tomen/c1ec4e0b15cf7aa61f448455905c6447 (this is a stringified version of the object)

The stream does its work and deepeer down the stack we meet defaultExecuteHandler() where the .map() portion of the code gets called.

After that, I think the sequence portion of the stream shall be handled and this is where the error occurs. In index.js line 3457 the method Stream.prototype.sequence is called and checks if the object is an stream, which it is not, then if the object is an array, which is it not. So it jumps into the else part in line 3501 and creates the error. Which then gets pushed down the stack until it is emitted.

So from my point of view defaultExecuteHandler() maps the object (sets the objectMode boolean) and after that when sequence() is called an exception is thrown.

emit (events.js:183)
(anonymous function) (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1891)
(anonymous function) (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1576)
s._send (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1532)
Stream.write (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1630)
Stream._send (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:959)
push (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1498)
(anonymous function) (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:3876)
s._send (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1532)
Stream.write (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1630)
Stream._send (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:959)
Stream.write (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1630)
(anonymous function) (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:679)
(anonymous function) (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:3504)
(anonymous function) (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1576)
s._send (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1532)
Stream.write (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1633)
Stream._send (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:959)
push (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1498)
(anonymous function) (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:2104)
s._send (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1532)
Stream.write (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1633)
Stream._send (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:959)
push (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1498)
(anonymous function) (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1791)
s._send (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1532)
Stream.write (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1633)
Stream._send (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:959)
Stream.write (d:\code\gremlin-javascript\gremlin-client\node_modules\highland\lib\index.js:1633)
ondata (d:\code\gremlin-javascript\gremlin-client\node_modules\readable-stream\lib\_stream_readable.js:612)
emitOne (events.js:116)
emit (events.js:211)
addChunk (d:\code\gremlin-javascript\gremlin-client\node_modules\readable-stream\lib\_stream_readable.js:284)
readableAddChunk (d:\code\gremlin-javascript\gremlin-client\node_modules\readable-stream\lib\_stream_readable.js:271)
Readable.push (d:\code\gremlin-javascript\gremlin-client\node_modules\readable-stream\lib\_stream_readable.js:238)
handleProtocolMessage (d:\code\gremlin-javascript\gremlin-client\lib\GremlinClient.js:168)
connection.on.message (d:\code\gremlin-javascript\gremlin-client\lib\GremlinClient.js:112)
emitOne (events.js:116)
emit (events.js:211)
handleMessage (d:\code\gremlin-javascript\gremlin-client\lib\WebSocketGremlinConnection.js:45)
WebSocketGremlinConnection.ws.onmessage.message (d:\code\gremlin-javascript\gremlin-client\lib\WebSocketGremlinConnection.js:30)
onMessage (d:\code\gremlin-javascript\gremlin-client\node_modules\ws\lib\EventTarget.js:103)
emitTwo (events.js:126)
emit (events.js:214)
_receiver.onmessage (d:\code\gremlin-javascript\gremlin-client\node_modules\ws\lib\WebSocket.js:146)
dataMessage (d:\code\gremlin-javascript\gremlin-client\node_modules\ws\lib\Receiver.js:380)
getData (d:\code\gremlin-javascript\gremlin-client\node_modules\ws\lib\Receiver.js:330)
startLoop (d:\code\gremlin-javascript\gremlin-client\node_modules\ws\lib\Receiver.js:165)
add (d:\code\gremlin-javascript\gremlin-client\node_modules\ws\lib\Receiver.js:139)
_ultron.on (d:\code\gremlin-javascript\gremlin-client\node_modules\ws\lib\WebSocket.js:142)
emitOne (events.js:116)
emit (events.js:211)
addChunk (_stream_readable.js:263)
readableAddChunk (_stream_readable.js:250)
Readable.push (_stream_readable.js:208)
onread (net.js:594)
[ TCPWRAP ] (Unknown Source:undefined)
init (inspector_async_hook.js:19)
emitInitNative (async_hooks.js:472)
Socket.connect (net.js:1006)
connect (net.js:103)
createSocket (_http_agent.js:224)
addRequest (_http_agent.js:192)
ClientRequest (_http_client.js:258)
request (http.js:38)
get (http.js:42)
initAsClient (d:\code\gremlin-javascript\gremlin-client\node_modules\ws\lib\WebSocket.js:637)
WebSocket (d:\code\gremlin-javascript\gremlin-client\node_modules\ws\lib\WebSocket.js:70)
WebSocketGremlinConnection (d:\code\gremlin-javascript\gremlin-client\lib\WebSocketGremlinConnection.js:26)
createConnection (d:\code\gremlin-javascript\gremlin-client\lib\GremlinClient.js:102)
GremlinClient (d:\code\gremlin-javascript\gremlin-client\lib\GremlinClient.js:92)
createClient (d:\code\gremlin-javascript\gremlin-client\lib\index.js:43)
incubate (d:\code\smalldata_node\app.js:99)
(anonymous function) (d:\code\smalldata_node\app.js:147)
Module._compile (module.js:632)
Module._extensions..js (module.js:646)
Module.load (module.js:554)
tryModuleLoad (module.js:497)
Module._load (module.js:489)
Module.runMain (module.js:676)
startup (bootstrap_node.js:187)
(anonymous function) (bootstrap_node.js:608)

Tomen avatar Dec 18 '17 20:12 Tomen

It has something to do with the version of Tinkerpop Gremlin Server. I just tried Tinkerpop Gremlin Server 3.2.6 and it worked!

Tomen avatar Dec 18 '17 20:12 Tomen

Here is a diff of the 3.2.6 format (left) and the 3.3.0 format (right): https://www.diffchecker.com/V8dE9kCt

they changed the way how they render lists.

Tomen avatar Dec 18 '17 20:12 Tomen

Just a heads up, seeing this with AWS' new Neptune service that is still in beta. The data I'm getting back is definitely the "g:List" type on the right hand side of @Tomen's diff. Still new to the Gremlin space, but it sounds like this is related to Serialization, right?

dwelch2344 avatar Dec 26 '17 07:12 dwelch2344

You're right and this is related to serialization format, which this library doesn't support yet. That's a bit of work that will be addressed by the upcoming official JavaScript GLV which was merged into master: https://github.com/apache/tinkerpop/pull/695.

jbmusso avatar Apr 05 '18 21:04 jbmusso