Skip to content

Commit

Permalink
provide useful messages for all endpoint hook errors
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Dec 23, 2014
1 parent 730b64c commit 596db44
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions lib/package.js
Expand Up @@ -95,6 +95,8 @@ exports.locate = function(target) {
throw 'Repo `' + target.name + '` not found!';

throw 'Invalid endpoint locate response for %' + target.endpoint + '%';
}, function(e) {
throw 'Error locating `' + target.name + '`\n' + e;
});
}

Expand All @@ -118,7 +120,7 @@ exports.lookup = function(pkg) {
throw 'Repo `' + pkg.package + '` not found!';

if (!lookup.versions)
throw new Error('Invalid endpoint lookup response for %' + pkg.endpoint + '%');
throw 'Invalid endpoint lookup response for %' + pkg.endpoint + '%';

lookups[pkg.package] = lookup.versions;

Expand All @@ -129,6 +131,8 @@ exports.lookup = function(pkg) {

return pkg.copy().setVersion(lookupObj.version);
}
}, function(e) {
throw 'Error looking up `' + pkg.name + '`\n' + e;
});
}

Expand Down Expand Up @@ -434,9 +438,14 @@ exports.download = function(pkg, override, unlink, preload) {
ui.log('info', 'Downloading `' + pkg.exactName + '`');

if (endpoint.getPackageConfig)
Promise.resolve(endpoint.getPackageConfig(pkg.package, pkg.version, hash, meta))
Promise.resolve()
.then(function() {
return endpoint.getPackageConfig(pkg.package, pkg.version, hash, meta);
})
.then(function(_pjson) {
return derivePackageConfig(pkg, _pjson, override);
}, function(e) {
throw 'Error getting package config for `' + pkg.name + '`\n' + e;
})
.then(function(_pjson) {
getPackageConfigResolve(pjson = _pjson)
Expand Down Expand Up @@ -469,6 +478,8 @@ exports.download = function(pkg, override, unlink, preload) {
.then(function(_pjson) {
return derivePackageConfig(pkg, _pjson, override || {});
});
}, function(e) {
throw 'Error downloading `' + pkg.name + '`\n' + e;
})
.then(function(_pjson) {
if (_pjson)
Expand Down Expand Up @@ -522,7 +533,13 @@ function derivePackageConfig(pkg, pjson, override) {

var endpoint = ep.load(pkg.endpoint);
if (endpoint.processPackageConfig)
return endpoint.processPackageConfig(pjson);
return Promise.resolve()
.then(function() {
return endpoint.processPackageConfig(pjson);
})
.catch(function(e) {
throw 'Error processing package config for `' + pkg.name + '`\n' + e;
});
return pjson;
}
exports.derivePackageConfig = derivePackageConfig;
Expand All @@ -548,7 +565,13 @@ exports.processPackage = function(pkg, dir, pjson) {
.then(function() {
// now that we have the derived pjson, do the endpoint build
if (endpoint.build)
return endpoint.build(pjson, dir);
return Promise.resolve()
.then(function() {
return endpoint.build(pjson, dir);
})
.catch(function(e) {
throw 'Error building package `' + pkg.name + '`\n' + e;
});
})

// apply build operations from the package.json
Expand Down

0 comments on commit 596db44

Please sign in to comment.