Skip to content

Commit

Permalink
Do not swallow sync errors from commands event handlers, fixes bower#849
Browse files Browse the repository at this point in the history
.
  • Loading branch information
satazor committed Sep 4, 2013
1 parent 48e475c commit 0866c93
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 44 deletions.
6 changes: 4 additions & 2 deletions lib/commands/cache/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ function clean(endpoints, options, config) {
!names ? clearCompletion(config, logger) : null
])
.spread(function (entries) {
logger.emit('end', entries);
return entries;
})
.fail(function (error) {
.done(function (entries) {
logger.emit('end', entries);
}, function (error) {
logger.emit('error', error);
});

Expand Down
6 changes: 4 additions & 2 deletions lib/commands/cache/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ function list(packages, options, config) {
});
}

logger.emit('end', entries);
return entries;
})
.fail(function (error) {
.done(function (entries) {
logger.emit('end', entries);
}, function (error) {
logger.emit('error', error);
});

Expand Down
6 changes: 4 additions & 2 deletions lib/commands/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ function home(name, config) {
}

open(homepage);
logger.emit('end', homepage);
return homepage;
})
.fail(function (error) {
.done(function (homepage) {
logger.emit('end', homepage);
}, function (error) {
logger.emit('error', error);
});

Expand Down
10 changes: 6 additions & 4 deletions lib/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ function info(endpoint, property, config) {
])
.spread(function (pkgMeta, versions) {
if (versions) {
return logger.emit('end', {
return {
name: decEndpoint.source,
versions: versions,
latest: pkgMeta
});
};
}

logger.emit('end', pkgMeta);
return pkgMeta;
})
.fail(function (error) {
.done(function (result) {
logger.emit('end', result);
}, function (error) {
logger.emit('error', error);
});

Expand Down
5 changes: 2 additions & 3 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ function init(config) {
.spread(setDependencies.bind(null, project))
// All done!
.spread(saveJson.bind(null, project, logger))
.then(function (json) {
.done(function (json) {
logger.emit('end', json);
})
.fail(function (error) {
}, function (error) {
logger.emit('error', error);
});

Expand Down
5 changes: 2 additions & 3 deletions lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ function install(endpoints, options, config) {
});

project.install(decEndpoints, options)
.then(function (installed) {
.done(function (installed) {
logger.emit('end', installed);
})
.fail(function (error) {
}, function (error) {
logger.emit('error', error);
});

Expand Down
16 changes: 10 additions & 6 deletions lib/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ function linkSelf(config) {
return createLink(src, dst);
})
.then(function () {
logger.emit('end', {
return {
src: src,
dst: dst
});
};
});
})
.fail(function (error) {
.done(function (result) {
logger.emit('end', result);
}, function (error) {
logger.emit('error', error);
});

Expand All @@ -58,12 +60,14 @@ function linkTo(name, localName, config) {
return createLink(src, dst);
})
.then(function () {
logger.emit('end', {
return {
src: src,
dst: dst
});
};
})
.fail(function (error) {
.done(function (result) {
logger.emit('end', result);
}, function (error) {
logger.emit('error', error);
});

Expand Down
10 changes: 6 additions & 4 deletions lib/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,23 @@ function list(options, config) {

// Render paths?
if (options.paths) {
return logger.emit('end', paths(flattened));
return paths(flattened);
}

// Do not check for new versions?
if (config.offline) {
return logger.emit('end', tree);
return tree;
}

// Check for new versions
return checkVersions(project, tree, logger)
.then(function () {
logger.emit('end', tree);
return tree;
});
})
.fail(function (error) {
.done(function (value) {
logger.emit('end', value);
}, function (error) {
logger.emit('error', error);
});

Expand Down
8 changes: 5 additions & 3 deletions lib/commands/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ function lookup(name, config) {
.then(function (entry) {
// TODO: Handle entry.type.. for now it's only 'alias'
// When we got published packages, this needs to be adjusted
logger.emit('end', !entry ? null : {
return !entry ? null : {
name: name,
url: entry && entry.url
});
};
})
.fail(function (error) {
.done(function (result) {
logger.emit('end', result);
}, function (error) {
logger.emit('error', error);
});

Expand Down
5 changes: 2 additions & 3 deletions lib/commands/prune.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ function prune(config) {
project = new Project(config, logger);

clean(project)
.then(function (removed) {
.done(function (removed) {
logger.emit('end', removed);
})
.fail(function (error) {
}, function (error) {
logger.emit('error', error);
});

Expand Down
5 changes: 2 additions & 3 deletions lib/commands/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ function register(name, url, config) {

return Q.nfcall(registryClient.register.bind(registryClient), name, url);
})
.then(function (result) {
.done(function (result) {
logger.emit('end', result);
})
.fail(function (error) {
}, function (error) {
logger.emit('error', error);
});
});
Expand Down
5 changes: 2 additions & 3 deletions lib/commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ function search(name, config) {
}

promise
.then(function (results) {
.done(function (results) {
logger.emit('end', results);
})
.fail(function (error) {
}, function (error) {
logger.emit('error', error);
});

Expand Down
5 changes: 2 additions & 3 deletions lib/commands/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ function uninstall(names, options, config) {
return clean(project, children, uninstalled);
});
})
.then(function (uninstalled) {
.done(function (uninstalled) {
logger.emit('end', uninstalled);
})
.fail(function (error) {
}, function (error) {
logger.emit('error', error);
});

Expand Down
5 changes: 2 additions & 3 deletions lib/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ function update(names, options, config) {
}

project.update(names, options)
.then(function (installed) {
.done(function (installed) {
logger.emit('end', installed);
})
.fail(function (error) {
}, function (error) {
logger.emit('error', error);
});

Expand Down

0 comments on commit 0866c93

Please sign in to comment.