diff --git a/lib/schema/documentarray.js b/lib/schema/documentarray.js index 47f2216325f..15537a5f935 100644 --- a/lib/schema/documentarray.js +++ b/lib/schema/documentarray.js @@ -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); } diff --git a/test/document.test.js b/test/document.test.js index cc0c81bb95c..16137a6bc5b 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -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);