Skip to content

Commit

Permalink
fix(document): surface errors in subdoc pre validate
Browse files Browse the repository at this point in the history
Fix #7187
  • Loading branch information
vkarpov15 committed Nov 2, 2018
1 parent 87005a1 commit 8f16b67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/schema/documentarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ DocumentArray.prototype.doValidate = function(array, fn, scope, options) {
// them :(

function callback(err) {
if (err) {
if (err != null) {
error = err;
if (error.name !== 'ValidationError') {
error.$isArrayValidatorError = true;
}
}
--count || fn(error);
}
Expand Down
4 changes: 2 additions & 2 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6379,11 +6379,11 @@ describe('document', function() {

it('surfaces errors in subdoc pre validate (gh-7187)', function() {
const InnerSchema = new Schema({ name: String });

InnerSchema.pre('validate', function() {
throw new Error('Oops!');
});

const TestSchema = new Schema({ subdocs: [InnerSchema] });

const Test = db.model('gh7187', TestSchema);
Expand Down

0 comments on commit 8f16b67

Please sign in to comment.