meteor-collection-hooks icon indicating copy to clipboard operation
meteor-collection-hooks copied to clipboard

logic error in error reporting on upsert failure

Open eymiha opened this issue 1 year ago • 1 comments

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.

eymiha avatar Oct 11 '24 21:10 eymiha

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.

github-actions[bot] avatar Oct 11 '24 21:10 github-actions[bot]

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

jankapunkt avatar Nov 21 '24 19:11 jankapunkt

@jankapunkt was this fixed?

StorytellerCZ avatar Jan 18 '25 09:01 StorytellerCZ

Yes in https://github.com/Meteor-Community-Packages/meteor-collection-hooks/pull/319

jankapunkt avatar Jan 18 '25 10:01 jankapunkt