Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

logic error in error reporting on upsert failure #316

Open eymiha opened 1 month ago

eymiha commented 1 month ago

in 1.3.2, in os/upsert.js, at line 82,

...
const wrappedCallback = function (err, ret) {
  if (err || (ret && ret.insertedId)) {
    // Send any errors to afterInsert
    afterInsert(ret.insertedId, err)
  } else {
...

In the function, if err is truthy, ret may still be undefined. Control will flow into the afterInsert, but ret.insertedId will fail to dereference ret and throw it's own error.

At this point, we are blocked as we can't apply the error to the upsert that caused it. So just record it to the server console, I suppose...

...
const wrappedCallback = function (err, ret) {
  if (err) {
    if (ret && ret.insertedId) {
      // Send any errors to afterInsert
      afterInsert(ret.insertedId, err)
    } else {
      // unable to recover the id, we need to punt.
      console.error(err);
    }
  } else {
...

This error seems to be in all releases of the package. I can only suppose that the problem went unnoticed based on the relative rarity of upserts and the added rarity of problems when upserting.

github-actions[bot] commented 1 month ago

Thank you for submitting this issue!

We, the Members of Meteor Community Packages take every issue seriously. Our goal is to provide long-term lifecycles for packages and keep up with the newest changes in Meteor and the overall NodeJs/JavaScript ecosystem.

However, we contribute to these packages mostly in our free time. Therefore, we can't guarantee you issues to be solved within certain time.

If you think this issue is trivial to solve, don't hesitate to submit a pull request, too! We will accompany you in the process with reviews and hints on how to get development set up.

Please also consider sponsoring the maintainers of the package. If you don't know who is currently maintaining this package, just leave a comment and we'll let you know.

jankapunkt commented 1 week ago

Attempted fix is in tun pipeline: https://github.com/Meteor-Community-Packages/meteor-collection-hooks/pull/319