Permalink
Browse files

Set the er.code for npm-specific errors, and s/EENGINE/ENOTSUP/

  • Loading branch information...
1 parent f7b6671 commit 7ea7f2d6564d21c5a1703bbbc3bd33435b103153 @isaacs isaacs committed Oct 3, 2011
Showing with 15 additions and 4 deletions.
  1. +1 −1 lib/install.js
  2. +13 −2 lib/utils/error-handler.js
  3. +1 −1 npm.js
View
@@ -491,7 +491,7 @@ function checkEngine (target, cb) {
if (eng.node && !semver.satisfies(nodev, eng.node)
|| eng.npm && !semver.satisfies(npmv, eng.npm)) {
var er = new Error("Unsupported")
- er.errno = npm.EENGINE
+ er.errno = npm.ENOTSUP
er.required = eng
er.pkgid = target._id
return cb(er)
View
@@ -56,6 +56,7 @@ function errorHandler (er) {
}
switch (er.errno) {
+ case "ECONNREFUSED":
case constants.ECONNREFUSED:
log.error(er)
log.error(["If you are using Cygwin, please set up your /etc/resolv.conf"
@@ -67,6 +68,8 @@ function errorHandler (er) {
].join("\n"))
break
+ case "EACCES":
+ case "EPERM":
case constants.EACCES:
case constants.EPERM:
log.error(er)
@@ -83,6 +86,7 @@ function errorHandler (er) {
break
case npm.ELIFECYCLE:
+ er.code = "ELIFECYCLE"
log.error(er.message)
log.error(["","Failed at the "+er.pkgid+" "+er.stage+" script."
,"This is most likely a problem with the "+er.pkgname+" package,"
@@ -96,6 +100,7 @@ function errorHandler (er) {
break
case npm.EJSONPARSE:
+ er.code = "EJSONPARSE"
log.error(er.message)
log.error("File: "+er.file)
log.error(["Failed to parse package.json data."
@@ -106,6 +111,7 @@ function errorHandler (er) {
break
case npm.E404:
+ er.code = "E404"
if (er.pkgid && er.pkgid !== "-") {
var msg = ["'"+er.pkgid+"' is not in the npm registry."
,"You could maybe bug the author to publish it"]
@@ -122,6 +128,7 @@ function errorHandler (er) {
break
case npm.EPUBLISHCONFLICT:
+ er.code = "EPUBLISHCONFLICT"
log.error(["Cannot publish over existing version."
,"Bump the 'version' field, set the --force flag, or"
," npm unpublish '"+er.pkgid+"'"
@@ -130,6 +137,7 @@ function errorHandler (er) {
break
case npm.EISGIT:
+ er.code = "EISGIT"
log.error([er.message
," "+er.path
,"Refusing to remove it. Update manually,"
@@ -138,14 +146,16 @@ function errorHandler (er) {
break
case npm.ECYCLE:
+ er.code = "ECYCLE"
log.error([er.message
,"While installing: "+er.pkgid
,"Found a pathological dependency case that npm cannot solve."
,"Please report this to the package author."
].join("\n"))
break
- case npm.EENGINE:
+ case npm.ENOTSUP:
+ er.code = "ENOTSUP"
log.error([er.message
,"Not compatible with your version of node/npm: "+er.pkgid
,"Required: "+JSON.stringify(er.required)
@@ -155,6 +165,7 @@ function errorHandler (er) {
].join("\n"))
break
+ case "EEXIST":
case constants.EEXIST:
log.error([er.message
,"File exists: "+er.path
@@ -184,7 +195,7 @@ function errorHandler (er) {
if (er.type) log.error(er.type, "type")
if (er.arguments) log.error(er.arguments, "arguments")
if (er.code) log.error(er.code, "code")
- if (er.errno) log.error(er.errno, "errno")
+ if (er.errno && typeof er.errno !== "object") log.error(er.errno, "errno")
exit(typeof er.errno === "number" ? er.errno : 1)
}
View
2 npm.js
@@ -28,7 +28,7 @@ npm.EPUBLISHCONFLICT = {}
npm.EJSONPARSE = {}
npm.EISGIT = {}
npm.ECYCLE = {}
-npm.EENGINE = {}
+npm.ENOTSUP = {}
// HACK for windows
if (process.platform === "win32") {

0 comments on commit 7ea7f2d

Please sign in to comment.