-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
backwards-breakingdeveloper-experienceThis issue improves error messages, debugging, or reportingThis issue improves error messages, debugging, or reporting
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the issue has not already been raised
Issue
Followup ticket to #15298, #15312: ensuring we use async functions all the way through for improved stack traces. The goal is for the following script to show a full async stack trace with a pointer to the line of the original doc.save() call.
Error.stackTraceLimit = 20;
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/mongoose_test");
const userSchema = new mongoose.Schema({
name: { type: String, required: true, validate: v => v.length > 3 },
age: Number,
});
userSchema.pre('validate', function() {
if (this.name === 'secret') {
throw new Error('name cannot be secret');
}
});
const User = mongoose.model("User", userSchema);
async function runDemo() {
const doc = new User({ name: 'A' });
// await doc.validate().catch(err => console.log('Validate', err));
await doc.save().catch(err => console.log('Save', err));
}
runDemo().catch(err => console.log(err.stack));And ensure support for similar cases:
find()findOne()updateOne()findOneAndUpdate()insertMany()bulkWrite()Model.validate()save()with user-defined pre hook that throws an errorsave()with user-defined post hook that throws an error
Metadata
Metadata
Assignees
Labels
backwards-breakingdeveloper-experienceThis issue improves error messages, debugging, or reportingThis issue improves error messages, debugging, or reporting