Skip to content

Commit

Permalink
fix(document): catch sync errors in document pre hooks and report as …
Browse files Browse the repository at this point in the history
…error

Fix #5738
  • Loading branch information
vkarpov15 committed Oct 27, 2017
1 parent 1d87987 commit 9e3427a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"async": "2.1.4",
"bson": "~1.0.4",
"hooks-fixed": "2.0.0",
"hooks-fixed": "2.0.2",
"kareem": "1.5.0",
"mongodb": "2.2.33",
"mpath": "0.3.0",
Expand Down
20 changes: 20 additions & 0 deletions test/document.hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,26 @@ describe('document: hooks:', function() {
done();
});

it('sync exceptions get passed as errors (gh-5738)', function(done) {
var bookSchema = new Schema({ title: String });

/* eslint-disable no-unused-vars */
bookSchema.pre('save', function(next) {
throw new Error('woops!');
});

var Book = mongoose.model('gh5738', bookSchema);

var book = new Book({});

book.title = 'Professional AngularJS';
book.save(function(error) {
assert.ok(error);
assert.equal(error.message, 'woops!');
done();
});
});

it('nested subdocs only fire once (gh-3281)', function(done) {
var L3Schema = new Schema({
title: String
Expand Down

0 comments on commit 9e3427a

Please sign in to comment.