Skip to content

Commit

Permalink
added VersionError
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Nov 13, 2012
1 parent 6eecdad commit 620451f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
31 changes: 31 additions & 0 deletions lib/errors/version.js
Original file line number Diff line number Diff line change
@@ -0,0 1,31 @@

/*!
* Module dependencies.
*/

var MongooseError = require('../error');

/**
* Version Error constructor.
*
* @inherits MongooseError
* @api private
*/

function VersionError () {
MongooseError.call(this, 'No matching document found.');
Error.captureStackTrace(this, arguments.callee);
this.name = 'VersionError';
};

/*!
* Inherits from MongooseError.
*/

VersionError.prototype.__proto__ = MongooseError.prototype;

/*!
* exports
*/

module.exports = VersionError;
3 changes: 2 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 6,7 @@ var Document = require('./document')
, MongooseArray = require('./types/array')
, MongooseBuffer = require('./types/buffer')
, MongooseError = require('./error')
, VersionError = require('./errors/version')
, Query = require('./query')
, Schema = require('./schema')
, utils = require('./utils')
Expand Down Expand Up @@ -321,7 322,7 @@ function handleSave (promise, self) {
}
} else {
// the update failed. pass an error back
promise.error(new Error('No matching document found.'));
promise.error(new VersionError);
promise = self = null;
return;
}
Expand Down
1 change: 1 addition & 0 deletions test/versioning.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 227,7 @@ describe('versioning', function(){
}

function test12 (err, a, b) {
assert.ok(err instanceof VersionError);
assert.ok(/No matching document/.test(err), 'changes to b should not be applied');
assert.equal(5, a.comments.length);

Expand Down

0 comments on commit 620451f

Please sign in to comment.