Skip to content

Commit b539608

Browse files
committed
🐛 Fix error handling in _fetchCreateOpVersion()
We're currently not returning errors from the database adapter if there are issues fetching the committed op, because of a code typo. This change adds coverage for this case and fixes the bug.
1 parent 3cdecf4 commit b539608

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

lib/submit-request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ SubmitRequest.prototype.submit = function(callback) {
110110
// must get the past ops and check their src and seq values to
111111
// differentiate.
112112
request._fetchCreateOpVersion(function(error, version) {
113-
if (err) return callback(err);
113+
if (error) return callback(error);
114114
if (version == null) {
115115
callback(request.alreadyCreatedError());
116116
} else {

test/client/submit.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var deserializedType = require('./deserialized-type');
66
var numberType = require('./number-type');
77
var errorHandler = require('../util').errorHandler;
88
var richText = require('rich-text');
9-
var MemoryDB = require('../../lib/db/memory');
109
types.register(deserializedType.type);
1110
types.register(deserializedType.type2);
1211
types.register(numberType.type);
@@ -215,8 +214,8 @@ module.exports = function() {
215214

216215
describe('no snapshot metadata available', function() {
217216
beforeEach(function() {
218-
var getSnapshot = MemoryDB.prototype.getSnapshot;
219-
sinon.stub(MemoryDB.prototype, 'getSnapshot')
217+
var getSnapshot = this.backend.db.getSnapshot;
218+
sinon.stub(this.backend.db, 'getSnapshot')
220219
.callsFake(function() {
221220
var args = Array.from(arguments);
222221
var callback = args.pop();
@@ -233,6 +232,27 @@ module.exports = function() {
233232
});
234233

235234
runCreateTests();
235+
236+
it('returns errors if the database cannot get committed op version', function(done) {
237+
sinon.stub(this.backend.db, 'getCommittedOpVersion')
238+
.callsFake(function() {
239+
var args = Array.from(arguments);
240+
var callback = args.pop();
241+
callback(new Error('uh-oh'));
242+
});
243+
244+
var doc1 = this.backend.connect().get('dogs', 'fido');
245+
var doc2 = this.backend.connect().get('dogs', 'fido');
246+
async.series([
247+
doc1.create.bind(doc1, {age: 3}),
248+
function(next) {
249+
doc2.create({name: 'Fido'}, function(error) {
250+
expect(error.message).to.equal('uh-oh');
251+
next();
252+
});
253+
}
254+
], done);
255+
});
236256
});
237257

238258
function runCreateTests() {

0 commit comments

Comments
 (0)