Skip to content

Commit

Permalink
fix: should not throw error when pass null (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore authored and fengmk2 committed Feb 12, 2017
1 parent 18efcbb commit c38468d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/ready.js
Expand Up @@ -80,6 +80,9 @@ class Ready extends EventEmitter {
opt.name = name || cacheKey;
const timer = setTimeout(() => this.emit('ready_timeout', opt.name), opt.timeout);
const cb = once(err => {
if (err != null && !(err instanceof Error)) {
err = new Error(err);
}
clearTimeout(timer);
// won't continue to fire after it's error
if (this.isError === true) return;
Expand All @@ -102,11 +105,8 @@ class Ready extends EventEmitter {
* @return {Ready} this
*/
readyDone(id, opt, err) {
if (err !== undefined && !opt.isWeakDep) {
if (err != null && !opt.isWeakDep) {
this.isError = true;
if (!(err instanceof Error)) {
err = new Error(err);
}
debug('[%s] Throw error task id `%s`, error %s', id, opt.name, err);
return this.emit('error', err);
}
Expand Down
3 changes: 3 additions & 0 deletions test/ready.test.js
Expand Up @@ -406,6 +406,9 @@ describe('Ready', function() {
err = yield assertErrorType(true);
assert(err.message === 'true');

err = yield assertErrorType(null);
assert(err === undefined);

function assertErrorType(value) {
const obj = {};
const ready = new Ready();
Expand Down

0 comments on commit c38468d

Please sign in to comment.