From a7612a8828b39e1e87ecd9c4c67a74fe7fe2dfe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Wed, 21 Nov 2012 22:42:59 +0000 Subject: [PATCH] Catch errors also while installing, fix mute deps. --- lib/core/manager.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/core/manager.js b/lib/core/manager.js index 97de1947..ef71c672 100644 --- a/lib/core/manager.js +++ b/lib/core/manager.js @@ -95,8 +95,12 @@ Manager.prototype.resolveLocal = function () { if (err) return this.emit('error', err); dirs.forEach(function (dir) { var name = path.basename(dir); + var pkg = new Package(name, dir, this); this.dependencies[name] = []; - this.dependencies[name].push(new Package(name, dir, this)); + this.dependencies[name].push(pkg); + pkg.on('error', function (err, origin) { + this.errors.push({ pkg: origin, error: err }); + }.bind(this)); }.bind(this)); this.emit('resolveLocal'); }.bind(this)); @@ -116,11 +120,11 @@ Manager.prototype.resolveEndpoints = function () { var pkg = new Package(name, endpoint, this); this.dependencies[name] = this.dependencies[name] || []; this.dependencies[name].push(pkg); - pkg.once('resolve', next).resolve(); - pkg.once('error', function (err) { - this.errors.push({ pkg: pkg, error: err }); + pkg.on('error', function (err, origin) { + this.errors.push({ pkg: origin, error: err }); next(); }.bind(this)); + pkg.once('resolve', next).resolve(); }.bind(this), this.emit.bind(this, 'resolveEndpoints')); return this; @@ -140,11 +144,11 @@ Manager.prototype.resolveFromJson = function () { var pkg = new Package(name, endpoint, this); this.dependencies[name] = this.dependencies[name] || []; this.dependencies[name].push(pkg); - pkg.once('resolve', next).resolve(); - pkg.once('error', function (err) { - this.errors.push({ pkg: pkg, error: err }); + pkg.on('error', function (err, origin) { + this.errors.push({ pkg: origin, error: err }); next(); }.bind(this)); + pkg.once('resolve', next).resolve(); }.bind(this), this.emit.bind(this, 'resolveFromJson')); }.bind(this)).loadJSON(); @@ -182,14 +186,20 @@ Manager.prototype.prune = function () { Manager.prototype.install = function () { async.forEach(Object.keys(this.dependencies), function (name, next) { - this.dependencies[name][0].once('install', next).install(); - }.bind(this), this.emit.bind(this, 'install')); + var pkg = this.dependencies[name][0]; + pkg.once('install', next).install(); + pkg.once('error', next); + }.bind(this), function () { + if (this.errors.length) this.reportErrors(); + return this.emit.bind(this, 'install'); + }.bind(this)); }; Manager.prototype.muteDependencies = function () { for (var name in this.dependencies) { this.dependencies[name].forEach(function (pkg) { pkg.removeAllListeners(); + pkg.on('error', function () {}); }); } };