Skip to content
Browse files

On a 404, specify the parent package if it exists

Fixes #4340. The error gets a `parent` property, and the message output displays
that.
  • Loading branch information...
1 parent 1e6f2a7 commit 8b4bb4815d80a3612186dc5549d698e7b988eb03 @evanlucas evanlucas committed with domenic Dec 19, 2013
Showing with 53 additions and 1 deletion.
  1. +1 −1 lib/install.js
  2. +3 −0 lib/utils/error-handler.js
  3. +49 −0 test/tap/404-parent.js
View
2 lib/install.js
@@ -714,7 +714,7 @@ function targetResolver (where, context, deps) {
}
if (data && !data._from) data._from = what
-
+ if (er && parent && parent.name) er.parent = parent.name
return cb(er, data || [])
})
}
View
3 lib/utils/error-handler.js
@@ -149,6 +149,9 @@ function errorHandler (er) {
if (er.pkgid && er.pkgid !== "-") {
var msg = ["'"+er.pkgid+"' is not in the npm registry."
,"You should bug the author to publish it"]
+ if (er.parent) {
+ msg.push("It was specified as a dependency of '"+er.parent+"'")
+ }
if (er.pkgid.match(/^node[\.\-]|[\.\-]js$/)) {
var s = er.pkgid.replace(/^node[\.\-]|[\.\-]js$/g, "")
if (s !== er.pkgid) {
View
49 test/tap/404-parent.js
@@ -0,0 +1,49 @@
+var common = require('../common-tap.js')
+var test = require('tap').test
+var npm = require('../../')
+var osenv = require('osenv')
+var path = require('path')
+var fs = require('fs')
+var rimraf = require('rimraf')
+var mkdirp = require('mkdirp')
+var pkg = path.resolve(__dirname, '404-parent')
+
+test('404-parent: if parent exists, specify parent in error message', function(t) {
+ setup()
+ rimraf.sync(path.resolve(pkg, 'node_modules'))
+ performInstall(function(err) {
+ t.ok(err instanceof Error)
+ t.pass('error was returned')
+ t.ok(err.parent === '404-parent-test')
+ t.end()
+ })
+})
+
+test('cleanup', function(t) {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+ t.end()
+})
+
+function setup() {
+ mkdirp.sync(pkg)
+ mkdirp.sync(path.resolve(pkg, 'cache'))
+ fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({
+ author: 'Evan Lucas',
+ name: '404-parent-test',
+ version: '0.0.0',
+ description: 'Test for 404-parent',
+ dependencies: {
+ 'test-npm-404-parent-test': '*'
+ }
+ }), 'utf8')
+ process.chdir(pkg)
+}
+
+function performInstall(cb) {
+ npm.load(function() {
+ npm.commands.install(pkg, [], function(err) {
+ cb(err)
+ })
+ })
+}

3 comments on commit 8b4bb48

@tj
tj commented on 8b4bb48 Dec 23, 2013

<3

@tj
tj commented on 8b4bb48 Jan 22, 2014

not sure this actually works haha, doesn't seem to be for me at least, I still have to check npm-debug.log

@evanlucas

hmm I actually just had it pop up a couple hours ago. Find anything in npm-debug.log?

Please sign in to comment.
Something went wrong with that request. Please try again.