scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

wrong return value from BaseDocument#_getHookPromises (array of arrays of promise instead of array of promise) #57

Closed royaltm closed 8 years ago

royaltm commented 8 years ago

Long story short: this really ruined my night: https://github.com/scottwrobinson/camo/blob/b2bd9846234a1fe969e4f8385cdcf7ba66fffc5a/lib/base-document.js#L541

The typeless at its worst...

this will push an array with (a possible) promise into an array

hookPromises.push(_.invoke([this], hookName));

resulting in [[promise]] instead of [promise]

and this is bad, because Promise.all([[promise]]) immediately succeeds.

So any error in ANY of this document hook's promise will be (possible silently) discarded!

why just not

hookPromises.push(this[hookName]());

or at least:

hookPromises = hookPromises.concat(_.invoke([this], hookName));
scottwrobinson commented 8 years ago

Thanks for bringing this up. I should be able to try out your fix tomorrow.

Thanks!

scottwrobinson commented 8 years ago

Also, if you can post any code that shows the error that would be great. Thanks!

royaltm commented 8 years ago

here you go