Permalink
Browse files

better reporting in case of error + exit status

	modified:   TODO.md
	modified:   nmod
  • Loading branch information...
1 parent a147c18 commit 7c00f3dc01a8e43dc8947bb4d5b9ad7b1e941bd7 @jeromeetienne committed Mar 7, 2011
Showing with 22 additions and 3 deletions.
  1. +0 −1 TODO.md
  2. +22 −2 nmod
View
@@ -4,7 +4,6 @@
### TODO
-* nmod install notexistingpkg do a crash...
* allow a search
* curl "http://search.npmjs.org/_view/search?startkey=%22express%22&endkey=%22expressZZZZZZZZZZZZZZZZZZZ%22&reduce=false"
* http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options for docs
View
24 nmod
@@ -60,7 +60,7 @@ var utils = {
if( res.statusCode >= 300 && res.statusCode < 400 ){
utils.fetchUrl(res.headers.location, dataCb, errorCb)
return;
- }
+ }
res.setEncoding('binary');
res.on('data', function(chunk){
@@ -191,6 +191,10 @@ var tty_color = {};
exports.isTty = require('tty').isatty(stdoutFd);
exports.code = function(str){
+ if(!exports.isTty) return str;
+ return exports.fg_green + str + exports.all_off;
+ }
+ exports.error = function(str){
if(!exports.isTty) return str;
return exports.fg_red + str + exports.all_off;
}
@@ -469,6 +473,10 @@ var nmod = function(cmdline, cmdopts){
successCb = successCb || function(pkgVers){};
failureCb = failureCb || function(error){console.log("error", error); console.assert(false);}
getMetaJson(pkgName, function(metaJson){
+ if( 'error' in metaJson && 'reason' in metaJson ){
+ failureCb(metaJson.reason)
+ return;
+ }
var latestVers = metaJson['dist-tags'].latest;
if( semver.satisfies(latestVers, pkgVersRange) ){
successCb(latestVers);
@@ -506,6 +514,9 @@ var nmod = function(cmdline, cmdopts){
}
/**
+ *
+ * Used while installing from npm and from tar
+ *
* @param {String} pkgUrl the url of the package to fetch
* @param {String} pkgName the name of the package (display only ?)
* @param {String} pkgVers the version of the package
@@ -552,7 +563,7 @@ var nmod = function(cmdline, cmdopts){
prefixStr: prefixStr,
successCb: function(){
// display for the user
- process.stdout.write(tty_color.code(prefixStr+pkgName)+": installation completed\n");
+ process.stdout.write(tty_color.code(prefixStr+pkgName)+": installation completed. All is "+tty_color.code('OK')+"\n");
// notify the caller
successCb();
}
@@ -645,6 +656,15 @@ var nmod = function(cmdline, cmdopts){
//
installFromPkgUrl(pkgUrl, pkgName, pkgVers, pkgJson);
});
+ }, function(error){
+ process.stdout.write(tty_color.code(prefixStr+pkgName)+": ");
+ process.stdout.write(pkgVersRange === ">= 0.0.0"? "latest version": ("version "+pkgVersRange));
+ if(error === "document not found"){
+ process.stdout.write(tty_color.error(" cant be found")+"! ensure the package version exists\n");
+ }else{
+ process.stdout.write(" installation "+tty_color.error("failed!")+" due to "+tty_color.error(error)+"\n");
+ }
+ process.exit(-1);
});
}

0 comments on commit 7c00f3d

Please sign in to comment.