Skip to content

Commit

Permalink
Don't print the whole stack so often
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jul 24, 2012
1 parent df9f194 commit cf4f225
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/utils/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,22 @@ function errorHandler (er) {
var m = er.code || er.message.match(/^(?:Error: )?(E[A-Z]+)/)
if (m && !er.code) er.code = m

var didStack = false
var printStack = false
switch (er.code) {
case "ECONNREFUSED":
log.error("", er)
log.error("", ["\nIf you are behind a proxy, please make sure that the"
,"'proxy' config is set properly. See: 'npm help config'"
].join("\n"))
printStack = true
break

case "EACCES":
case "EPERM":
log.error("", er)
log.error("", ["\nPlease try running this command again as root/Administrator."
].join("\n"))
printStack = true
break

case "ELIFECYCLE":
Expand Down Expand Up @@ -209,7 +211,6 @@ function errorHandler (er) {
} // else passthrough

default:
didStack = true
log.error("", er.stack || er.message || er)
log.error("", ["If you need help, you may report this log at:"
," <http://github.com/isaacs/npm/issues>"
Expand All @@ -229,6 +230,9 @@ function errorHandler (er) {
log.error("node -v", process.version)
log.error("npm -v", npm.version)

// if we're not going to print it below, still save it to the log
if (!printStack) log.silly("stack", er.stack || er.message)

; [ "file"
, "path"
, "type"
Expand All @@ -246,7 +250,7 @@ function errorHandler (er) {
].forEach(function (k) {
var v = er[k]
if (k === "stack") {
if (didStack) return
if (!printStack) return
if (!v) v = er.message
}
if (!v) return
Expand Down

0 comments on commit cf4f225

Please sign in to comment.