diff options
author | isaacs <i@izs.me> | 2010-10-02 12:16:31 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-10-02 12:20:49 +0400 |
commit | c445a291a51d0cafdf453b61d6e129749dc10120 (patch) | |
tree | 8d86f77dcf944b055621417b4ade8edd3568a507 /cli.js | |
parent | a72ebbde52a7c86d64982fae5aa6179e9c16b946 (diff) |
Move error handling into a separate file, and add more support for common issues.
Diffstat (limited to 'cli.js')
-rwxr-xr-x | cli.js | 40 |
1 files changed, 1 insertions, 39 deletions
@@ -12,6 +12,7 @@ var fs = require("./lib/utils/graceful-fs") , npm = require("./npm") , ini = require("./lib/utils/ini") , rm = require("./lib/utils/rm-rf") + , errorHandler = require("./lib/utils/error-handler") // supported commands. , argv = process.argv.slice(2) @@ -64,10 +65,6 @@ if (!semver.satisfies(nodeVer, reqVer)) { } process.on("uncaughtException", errorHandler) -process.on("exit", function () { if (!itWorked) log.win("not ok") }) - -var itWorked = false - if (!command && !printVersion) conf.usage = true @@ -83,38 +80,3 @@ else { npm.commands[command](arglist, errorHandler) }) } - -var cbCalled = false -function errorHandler (er) { - if (cbCalled) throw new Error("Callback called more than once.") - cbCalled = true - if (!er) { - itWorked = true - log.win("ok") - return exit() - } - log.error(er) - if (!(er instanceof Error)) return exit(1) - if (er.message.trim() === "ECONNREFUSED, Could not contact DNS servers") { - log.error(["If you are using Cygwin, please set up your /etc/resolv.conf" - ,"See step 3 in this wiki page:" - ," http://github.com/ry/node/wiki/Building-node.js-on-Cygwin-%28Windows%29" - ,"If you are not using Cygwin, please report this" - ,"at <http://github.com/isaacs/npm/issues>" - ,"or email it to <npm-@googlegroups.com>" - ].join("\n")) - } else { - if (npm.commands[command].usage) { - log.error(npm.commands[command].usage) - } - log.error(["try running: 'npm help "+command+"'" - ,"Report this *entire* log at <http://github.com/isaacs/npm/issues>" - ,"or email it to <npm-@googlegroups.com>" - ].join("\n")) - } - exit(1) -} - -function exit (code) { - rm(npm.tmp, function () { process.exit(code || 0) }) -} |