Skip to content

Commit

Permalink
Catch bad put() values and add tests for bad put/add values
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Mar 26, 2016
1 parent 239ad11 commit 39f2860
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
6 changes: 5 additions & 1 deletion dist/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
record = record.item;
store.put(record, key);
} else {
store.put(record);
try {
store.put(record); // Can throw DataError, e.g., if function passed in
} catch (err) {
reject(err);
}
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion dist/db.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/db.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/db.min.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,11 @@
record = record.item;
store.put(record, key);
} else {
store.put(record);
try {
store.put(record); // Can throw DataError, e.g., if function passed in
} catch (err) {
reject(err);
}
}
});
});
Expand Down
18 changes: 18 additions & 0 deletions tests/specs/bad-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,24 @@
});
});

it('should catch bad values', function (done) {
db.open({server: this.dbName}).then(function (s) {
var caught = false;
var badValue = function () {};
// var badValue = NaN // This should cause an error to be thrown (a DataError error) per draft spec but doesn't in Chrome, Firefox, or PhantomJS
s.names.put(badValue).catch(function (err) {
expect(err.name).to.equal('DataCloneError');
// expect(err.name).to.equal('DataError'); // Will change to this per draft spec
caught = true;
return s.names.add(badValue);
}).catch(function (err) {
expect(err.name).to.equal('DataCloneError');
expect(caught).to.be.true;
done();
});
});
});

it('should catch bad range keys', function (done) {
var ct = 0;
var item = {
Expand Down

0 comments on commit 39f2860

Please sign in to comment.