Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-save hook silently swallows exception #9659

Closed
mizdler opened this issue Dec 5, 2020 · 0 comments
Closed

Pre-save hook silently swallows exception #9659

mizdler opened this issue Dec 5, 2020 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@mizdler
Copy link

mizdler commented Dec 5, 2020

It's a bug

What is the current behavior?
pre-save hook silently swallows the exceptions when we don't pass callback to function but according to documentation it shouldn't be a problem: https://mongoosejs.com/docs/middleware.html#error-handling

If the current behavior is a bug, please provide the steps to reproduce.

const Schema = mongoose.Schema;

describe('PreSave', function () {
	it('test pre save', async function () {
		const TestScheme = new Schema({name: String});
		TestScheme.pre('save', function () {
			throw new Error('test err');
		});
		const TestModel = mongoose.model('testModel', TestScheme);
		const testObject = new TestModel({name: 't'});
		try {
			await testObject.save();
		} catch (e) {
			// doesn't reach here!!
		}
	});
});

What is the expected behavior?
We must see the thrown error in catch section.

Node.js: 12.8.3
Mongoose: 5.11.4
MongoDB: 4.0.14

@vkarpov15 vkarpov15 added this to the 5.11.5 milestone Dec 6, 2020
@vkarpov15 vkarpov15 added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Dec 6, 2020
@vkarpov15 vkarpov15 modified the milestones: 5.11.5, 5.11.6 Dec 7, 2020
@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants