Skip to content
Browse files

Recognize error correctly

  • Loading branch information...
1 parent 191d9da commit 18269ffdefbc7db80f46c232d5722a52deeb3db2 @nakamura-to committed Jun 16, 2012
Showing with 10 additions and 10 deletions.
  1. 0 examples/{countDown.js → countdown.js}
  2. +3 −2 lib/gate.js
  3. +7 −8 test/{gate.js → gate_test.js}
View
0 examples/countDown.js → examples/countdown.js
File renamed without changes.
View
5 lib/gate.js
@@ -76,10 +76,11 @@ Async.prototype.makeCallback = function makeCallback(caller, name, mapping, skip
var next = self.next;
self.pending--;
if (!self.canceled) {
- if (error && typeof error === 'object' && !('gate_location' in error)) {
+ var isError = error instanceof Error;
+ if (isError && !('gate_location' in error)) {
error.gate_location = location;
}
- if (error && !skipErrorCheck) {
+ if (isError && !skipErrorCheck) {
self.canceled = true;
if (next) {
self.next = noop;
View
15 test/gate.js → test/gate_test.js
@@ -95,21 +95,21 @@ describe('latch', function() {
assert.strictEqual(0, g.count);
});
- it('should handle error', function (done) {
+ it('should handle non-error object', function (done) {
var g = gate.create();
- var callback = g.latch(1);
+ var callback = g.latch();
process.nextTick(function () {
callback('ERROR');
});
- g.await(function (err) {
- assert.strictEqual('ERROR', err);
+ g.await(function (err) {
+ if (err) throw err;
done();
});
});
it('should handle error object', function (done) {
var g = gate.create();
- var callback = g.latch(1);
+ var callback = g.latch();
process.nextTick(function () {
callback(new Error('ERROR'));
});
@@ -124,11 +124,10 @@ describe('latch', function() {
var g = gate.create();
var callback = g.latch(0, true);
process.nextTick(function () {
- callback('ERROR');
+ callback(new Error('ERROR'));
});
g.await(function (err, results) {
- if (err) throw err;
- assert.strictEqual('ERROR', results[0]);
+ assert.ok('ERROR', results[0].message);
done();
});
});

0 comments on commit 18269ff

Please sign in to comment.
Something went wrong with that request. Please try again.