From 8f16b67038f1a10afac8552d199228ef8f64cc9b Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 2 Nov 2018 09:33:08 -0400 Subject: [PATCH] fix(document): surface errors in subdoc pre validate Fix #7187 --- lib/schema/documentarray.js | 5 ++++- test/document.test.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) 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);