Throw clean error if save() called in parallel on same doc instance
See original GitHub issueI have seen a few issues closed already regarding the #save()
method and swallowing of exceptions. I’ve got this happening at the moment with the latest version in npm (4.4.12). Here’s some code:
const giftcard = new Giftcard({ // new instance of the model
// setting some properties here
});
giftcard.save((err) => {
if (err) throw new Error(err);
// this never happens - the callback is never called
});
I can post a more detailed example if required.
Edit: Also, this happens with the promise interface as well, so giftcard.save().then()
has the same result.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:61 (13 by maintainers)
Top Results From Across the Web
MongooseError [ParallelSaveError]: Can't save() the same doc ...
You have to create new instance of League each time. ... won't work inside forEach; You are calling res.send() every time you call...
Read more >Exception handling (Task Parallel Library) - Microsoft Learn
Explore exception handling using the Task Parallel Library (TPL) in .NET. See nested aggregate exceptions, inner exceptions, unobserved task ...
Read more >Pipeline: Basic Steps - Jenkins
The behavior of the step when an exception is thrown can be configured to print a message, set a build result other than...
Read more >Handling Error Conditions Using a Step Functions State ...
Ensure that your Lambda function is under the same AWS account and AWS Region as your state machine. Open the AWS Lambda console...
Read more >Top 10 Most Common Node.js Developer Mistakes - Toptal
js developers. Mistake #6: Throwing Errors from Inside Callbacks. JavaScript has the notion of exceptions. Mimicking the syntax of almost all traditional ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mtimofiiv @cwhenderson20 @dodekeract I have just donated over PayPal to @vkarpov15 (val@karpov.io) for his time helping me debug this issue. If you have been able to get passed this through our findings please send him some dough! 💸 He deserves it! He spent a ton of time with me, even while he was on his mobile phone he was helping!
@vkarpov15 I am experiencing this same issue on version 4.4.20. Attempting to call
save
on my model results in the callback never being called while running the same operation with$__save
works just fine.I am not overwriting promises and I do not have any pre-save (or otherwise) middleware for the model and using
mongoose.set("debug", true)
does not show anything strange. I have also verified that the document I’m attempting to save does pass validation.I have additionally attached a connection error handler to the mongoose instance and no errors are reported.
Example:
For now I will use the private method as I’m not sure of how to proceed otherwise, but if I can give any more information to help with this, please let me know.
Update Similar to @mtimofiiv,
console.log
-ing the methods$__save
andsave
give me the actual$__save
method as defined in model.js and a function calledwrappedPointCut
, respectively.Additionally, after modifying my installed version of mongoose (to log when methods are called) and re-running the code, I can see that indeed the
$__save
method reports that it is being called, while similar logging forsave
never reports.