Skip to content

Commit 8f16b67

Browse files
committed
fix(document): surface errors in subdoc pre validate
Fix #7187
1 parent 87005a1 commit 8f16b67

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/schema/documentarray.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,11 @@ DocumentArray.prototype.doValidate = function(array, fn, scope, options) {
164164
// them :(
165165

166166
function callback(err) {
167-
if (err) {
167+
if (err != null) {
168168
error = err;
169+
if (error.name !== 'ValidationError') {
170+
error.$isArrayValidatorError = true;
171+
}
169172
}
170173
--count || fn(error);
171174
}

test/document.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6379,11 +6379,11 @@ describe('document', function() {
63796379

63806380
it('surfaces errors in subdoc pre validate (gh-7187)', function() {
63816381
const InnerSchema = new Schema({ name: String });
6382-
6382+
63836383
InnerSchema.pre('validate', function() {
63846384
throw new Error('Oops!');
63856385
});
6386-
6386+
63876387
const TestSchema = new Schema({ subdocs: [InnerSchema] });
63886388

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

0 commit comments

Comments
 (0)