appscot / sails-orientdb

OrientDB adapter for Waterline / Sails.js ORM
MIT License
25 stars 23 forks source link

Duplicate call when error occurs in createEdge #115

Closed codecoded closed 2 years ago

codecoded commented 9 years ago

Hey

I've been trying to play with the promises in the createEdge, but they don't seem to recognise any errors coming back from OrientDB, just get consumed within the .then clause, with an empty argument (and .error doesn't ever get called)

So I reverted back to the callback (node style), and it seems to call the error twice. I'm simply logging out the error in the callback

    var cb;
    cb = function(err, result) {
      return console.log(err);
    };
    User.createEdge(user.id, follow_user.id, follow_edge, cb);

Orient throws a single error (duplicate key in this case)

Sent run-time exception to the client /127.0.0.1:50095: com.orientechnologies.orient.core.storage.ORecordDuplicatedException: Cannot index record #32:8: found duplicated key 'OCompositeKey{keys=[#12:25902, #12:25903]}' in index 'follows.in_out' previously assigned to the record #32:7 RID=#32:7 [ONetworkProtocolBinary]

yet the logs show multiple error output

{ [OrientDB.RequestError: Cannot index record #32:8: found duplicated key 'OCompositeKey{keys=[#12:25902, #12:25903]}' in index 'follows.in_out' previously assigned to the record #32:7]
  name: 'OrientDB.RequestError',
  message: 'Cannot index record #32:8: found duplicated key \'OCompositeKey{keys=[#12:25902, #12:25903]}\' in index \'follows.in_out\' previously assigned to the record #32:7',
  data: {},
  previous: [],
  id: 1,
  type: 'com.orientechnologies.orient.core.storage.ORecordDuplicatedException',
  hasMore: 0 }
{ [OrientDB.RequestError: Cannot index record #32:8: found duplicated key 'OCompositeKey{keys=[#12:25902, #12:25903]}' in index 'follows.in_out' previously assigned to the record #32:7]
  name: 'OrientDB.RequestError',
  message: 'Cannot index record #32:8: found duplicated key \'OCompositeKey{keys=[#12:25902, #12:25903]}\' in index \'follows.in_out\' previously assigned to the record #32:7',
  data: {},
  previous: [],
  id: 1,
  type: 'com.orientechnologies.orient.core.storage.ORecordDuplicatedException',
  hasMore: 0 }

I'm not sure if this is because of .nodeify call that's inserted into to the createEdge promise stream?

Any advice on this would be great. Never sure if this an issue or just my bad user implementation ;)

Thanks

Sky

dmarcelino commented 9 years ago

Hi @Soultripper,

Have you tried using catch instead of error? Something like:

  User.createEdge(user.id, follow_user.id, follow_edge)
  .then(/* ... */)
  .catch(function(err) {
    return console.log(err);
  });
codecoded commented 9 years ago

Hey @dmarcelino!

Yeah, I tried that too. It didn't reach catch either. It's always going to the .then function.

dmarcelino commented 9 years ago

Sounds like a bug, would you mind submitting a PR with a test? You can use 105-delete_customPK.js as a template.

codecoded commented 9 years ago

Hey!

Ok - will give it a go soon. Admittedly I'm not an active participant to the open source community, so this will be my first (Microsoft upbringing :P )

Just to let you know in the meantime, that I promisifed the User.createEdge and it worked as expected

    var createEdge = Promise.promisify(User.createEdge);
    return createEdge(user.id, follow_user.id, follow_edge)
    .then(...)
    .catch(...)

with catch having the db error as it's argument, and only logging once

{ [OrientDB.RequestError: Cannot index record #32:12: found duplicated key 'OCompositeKey{keys=[#12:25906, #12:25903]}' in index 'follows.in_out' previously assigned to the record #32:11]
  name: 'OrientDB.RequestError',
  message: 'Cannot index record #32:12: found duplicated key \'OCompositeKey{keys=[#12:25906, #12:25903]}\' in index \'follows.in_out\' previously assigned to the record #32:11',
  data: {},
  previous: [],
  id: 1,
  type: 'com.orientechnologies.orient.core.storage.ORecordDuplicatedException',
  hasMore: 0 }

Thanks