Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit 9c860f2

Browse files
watildeiarna
authored andcommitted
doctor: do not crash w/ registries that do not support ping
If registry doesn't support ping, npm doctor should display the information instead of stopping its investigation. Credit: @watilde PR-URL: #16021 Reviewed-By: @iarna
1 parent f08c663 commit 9c860f2

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

lib/doctor.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ function doctor (args, silent, cb) {
7272
}
7373

7474
function makePretty (p) {
75-
var ping = p[0] ? 'ok' : 'notOk'
76-
var npmLTS = p[1]
77-
var nodeLTS = p[2].replace('v', '')
78-
var whichGit = p[3] || 'not installed'
79-
var readbleCaches = p[4] ? 'ok' : 'notOk'
80-
var executableGlobalModules = p[5] ? 'ok' : 'notOk'
81-
var executableLocalModules = p[6] ? 'ok' : 'notOk'
82-
var checksumCachedFiles = p[7] ? 'ok' : 'notOk'
75+
var ping = p[1]
76+
var npmLTS = p[2]
77+
var nodeLTS = p[3].replace('v', '')
78+
var whichGit = p[4] || 'not installed'
79+
var readbleCaches = p[5] ? 'ok' : 'notOk'
80+
var executableGlobalModules = p[6] ? 'ok' : 'notOk'
81+
var executableLocalModules = p[7] ? 'ok' : 'notOk'
82+
var checksumCachedFiles = p[8] ? 'ok' : 'notOk'
8383
var npmV = npm.version
8484
var nodeV = process.version.replace('v', '')
8585
var registry = npm.config.get('registry')
@@ -95,7 +95,7 @@ function makePretty (p) {
9595
['Checksum cached files', checksumCachedFiles]
9696
]
9797

98-
if (ping !== 'ok') list[0][2] = 'Check your internet connection'
98+
if (p[0] !== 200) list[0][2] = 'Check your internet connection'
9999
if (!semver.satisfies(npmV, '>=' + npmLTS)) list[1][2] = 'Use npm v' + npmLTS
100100
if (!semver.satisfies(nodeV, '>=' + nodeLTS)) list[2][2] = 'Use node v' + nodeLTS
101101
if (registry !== defaultRegistry) list[3][2] = 'Try `npm config set registry ' + defaultRegistry + '`'

lib/doctor/check-ping.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ var ping = require('../ping.js')
44
function checkPing (cb) {
55
var tracker = log.newItem('checkPing', 1)
66
tracker.info('checkPing', 'Pinging registry')
7-
ping({}, true, function (err, pong) {
7+
ping({}, true, function (err, pong, data, res) {
88
tracker.finish()
9-
cb(err, pong)
9+
cb(null, [res.statusCode, res.statusMessage])
1010
})
1111
}
1212

lib/ping.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ function ping (args, silent, cb) {
1414
if (!registry) return cb(new Error('no default registry set'))
1515
var auth = npm.config.getCredentialsByURI(registry)
1616

17-
npm.registry.ping(registry, {auth: auth}, function (er, pong) {
17+
npm.registry.ping(registry, {auth: auth}, function (er, pong, data, res) {
1818
if (!silent) output(JSON.stringify(pong))
19-
cb(er, er ? null : pong)
19+
cb(er, er ? null : pong, data, res)
2020
})
2121
}

test/tap/doctor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test('npm doctor', function (t) {
5151
npm.commands.doctor({'node-url': node_url}, true, function (e, list) {
5252
t.ifError(e, 'npm loaded successfully')
5353
t.same(list.length, 9, 'list should have 9 prop')
54-
t.same(list[0][1], 'ok', 'npm ping')
54+
t.same(list[0][1], 'OK', 'npm ping')
5555
t.same(list[1][1], 'v' + npm.version, 'npm -v')
5656
t.same(list[2][1], process.version, 'node -v')
5757
t.same(list[3][1], common.registry + '/', 'npm config get registry')

0 commit comments

Comments
 (0)