Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2014-06-13 01:51:45 +0400
committerisaacs <i@izs.me>2014-06-13 01:51:45 +0400
commitaa620a8b5cdcba86046ac7474266fdd341021993 (patch)
tree66647e92937960a7d5f208509a6121520e03fc59 /lib
parent1ab43c9efa49ff40a2313958f4fdcee6459cd90e (diff)
Properly handle errors that can occur in the config-loading process
Diffstat (limited to 'lib')
-rw-r--r--lib/npm.js7
-rw-r--r--lib/utils/error-handler.js6
2 files changed, 8 insertions, 5 deletions
diff --git a/lib/npm.js b/lib/npm.js
index f2319bfd5..344e4d348 100644
--- a/lib/npm.js
+++ b/lib/npm.js
@@ -275,6 +275,8 @@ npm.load = function (cli, cb_) {
function cb (er) {
if (loadErr) return
+ loadErr = er
+ if (er) return cb_(er)
if (npm.config.get("force")) {
log.warn("using --force", "I sure hope you know what you are doing.")
}
@@ -307,6 +309,9 @@ function load (npm, cli, cb) {
npmconf.load(cli, builtin, function (er, config) {
if (er === config) er = null
+ npm.config = config
+ if (er) return cb(er)
+
// Include npm-version and node-version in user-agent
var ua = config.get("user-agent") || ""
ua = ua.replace(/\{node-version\}/gi, process.version)
@@ -315,8 +320,6 @@ function load (npm, cli, cb) {
ua = ua.replace(/\{arch\}/gi, process.arch)
config.set("user-agent", ua)
- npm.config = config
-
var color = config.get("color")
log.level = config.get("loglevel")
diff --git a/lib/utils/error-handler.js b/lib/utils/error-handler.js
index feeec184c..820bf07ad 100644
--- a/lib/utils/error-handler.js
+++ b/lib/utils/error-handler.js
@@ -13,7 +13,7 @@ var cbCalled = false
process.on("exit", function (code) {
// console.error("exit", code)
- if (!npm.config.loaded) return
+ if (!npm.config || !npm.config.loaded) return
if (code) itWorked = false
if (itWorked) log.info("ok")
else {
@@ -46,7 +46,7 @@ process.on("exit", function (code) {
function exit (code, noLog) {
exitCode = exitCode || process.exitCode || code
- var doExit = npm.config.get("_exit")
+ var doExit = npm.config ? npm.config.get("_exit") : true
log.verbose("exit", [code, doExit])
if (log.level === "silent") noLog = true
@@ -71,7 +71,7 @@ function exit (code, noLog) {
function errorHandler (er) {
var printStack = false
// console.error("errorHandler", er)
- if (!npm.config.loaded) {
+ if (!npm.config || !npm.config.loaded) {
// logging won't work unless we pretend that it's ready
er = er || new Error("Exit prior to config file resolving.")
console.error(er.stack || er.message)