Skip to content

Commit

Permalink
fix(model): remove $versionError from save options for better debug o…
Browse files Browse the repository at this point in the history
…utput

Fix Automattic#7570
  • Loading branch information
vkarpov15 committed Mar 8, 2019
1 parent a465059 commit ae82062
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const MongooseMap = require('./types/map');
const OverwriteModelError = require('./error').OverwriteModelError;
const PromiseProvider = require('./promise_provider');
const Query = require('./query');
const SaveOptions = require('./options/saveOptions');
const Schema = require('./schema');
const VersionError = require('./error').VersionError;
const ParallelSaveError = require('./error').ParallelSaveError;
Expand Down Expand Up @@ -362,7 +363,8 @@ Model.prototype.$__save = function(options, callback) {

if (numAffected <= 0) {
// the update failed. pass an error back
const err = options.$versionError || new VersionError(this, version, modifiedPaths);
const err = this.$__.$versionError ||
new VersionError(this, version, modifiedPaths);
return callback(err);
}

Expand Down Expand Up @@ -449,17 +451,12 @@ Model.prototype.save = function(options, fn) {
options = undefined;
}

if (options != null) {
options = utils.clone(options);
} else {
options = {};
}

if (fn) {
fn = this.constructor.$wrapCallback(fn);
}

options.$versionError = generateVersionError(this, this.modifiedPaths());
options = new SaveOptions(options);
this.$__.$versionError = generateVersionError(this, this.modifiedPaths());

return utils.promiseOrCallback(fn, cb => {
if (parallelSave) {
Expand Down
14 changes: 14 additions & 0 deletions lib/options/saveOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const utils = require('../utils');

class SaveOptions {
constructor(obj) {
if (obj == null) {
return;
}
Object.assign(this, utils.clone(obj));
}
}

module.exports = SaveOptions;

0 comments on commit ae82062

Please sign in to comment.