Skip to content

Commit

Permalink
Merge branch 'release/1.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanDonovan committed Oct 19, 2015
2 parents aa2b345 + 462d9ac commit eb52818
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions History.md
@@ -1,3 +1,6 @@
- 1.2.2 2015-10-19
- Bugfix: Fixing domain error issues when error is thrown inside 'work' function (#28).

- 1.2.1 2015-10-17
- Bugfix: multi-caching: using underlying store's isCacheableValue function when it exists (#34).

Expand Down
6 changes: 5 additions & 1 deletion lib/multi_caching.js
Expand Up @@ -163,7 +163,11 @@ var multiCaching = function(caches, options) {
domain
.create()
.on('error', function(err) {
callbackFiller.fill(key, err);
if (callbackFiller.has(key)) {
callbackFiller.fill(key, err);
} else {
cb(err);
}
})
.bind(work)(function(err, data) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "cache-manager",
"version": "1.2.1",
"version": "1.2.2",
"description": "Cache module for Node.js",
"main": "index.js",
"scripts": {
Expand Down
26 changes: 26 additions & 0 deletions test/multi_caching.unit.js
Expand Up @@ -388,6 +388,7 @@ describe("multiCaching", function() {
checkErr(err);
assert.deepEqual(widget, {name: name});
sinon.assert.calledWith(memoryCache3.store.set, key, {name: name}, {ttl: defaultTtl});

done();
});
});
Expand Down Expand Up @@ -866,6 +867,31 @@ describe("multiCaching", function() {
});
});

context("when an error is thrown in the work function's callback", function() {
var fakeError;

beforeEach(function() {
fakeError = new Error(support.random.string());
});

it("bubbles up that error", function(done) {
multiCache.wrap(key, function(next) {
next();
}, ttl, function() {
// This test as-is doesn't prove a fix for #28 (https://github.com/BryanDonovan/node-cache-manager/issues/28)
// but if you remove the try/catch, it shows that the undefined `waiting` array issue
// is no longer present (the domain doesn't try to process the error in the callbackFiller).
try {
throw new Error('foo');
} catch (e) {
assert.equal(e.message, 'foo');
}

done();
});
});
});

context("when store.get() calls back with an error", function() {
it("bubbles up that error", function(done) {
var fakeError = new Error(support.random.string());
Expand Down

0 comments on commit eb52818

Please sign in to comment.