Skip to content

Commit

Permalink
fix(document): fix test failures from fix for #8149
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Sep 12, 2019
1 parent b4d0303 commit 0aec7ad
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/document.js
Expand Up @@ -1111,7 +1111,7 @@ Document.prototype.$set = function $set(path, val, type, options) {

this.$markValid(path);
} catch (e) {
if (e instanceof MongooseError.StrictModeError) {
if (e instanceof MongooseError.StrictModeError && e.isImmutableError) {
this.invalidate(path, e);
} else {
this.invalidate(path,
Expand Down
3 changes: 2 additions & 1 deletion lib/error/strict.js
Expand Up @@ -15,11 +15,12 @@ const MongooseError = require('./');
* @api private
*/

function StrictModeError(path, msg) {
function StrictModeError(path, msg, immutable) {
msg = msg || 'Field `' + path + '` is not in schema and strict ' +
'mode is set to throw.';
MongooseError.call(this, msg);
this.name = 'StrictModeError';
this.isImmutableError = !!immutable;
if (Error.captureStackTrace) {
Error.captureStackTrace(this);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/schematype/handleImmutable.js
Expand Up @@ -35,7 +35,7 @@ function createImmutableSetter(path, immutable) {
}
if (this.$__.strictMode === 'throw' && v !== this[path]) {
throw new StrictModeError(path, 'Path `' + path + '` is immutable ' +
'and strict mode is set to throw.');
'and strict mode is set to throw.', true);
}

return this[path];
Expand Down

0 comments on commit 0aec7ad

Please sign in to comment.