Skip to content

Commit 769d2e0

Browse files
committed
fix: Better error on invalid --user/--group
This addresses the issue when people fail to install binary packages on Docker and other environments where there is no 'nobody' user. The Config.loadUid() method was failing in these cases, but not in a way that was particularly informative. Furthermore, the uid and gid resolved in that way were just ignored and never stored anywhere. However, until [email protected], an error from uid-number was _also_ ignored, so if we didn't crash somewhere, then it would run scripts as root when provided with an invalid user. This is arguably fine, but it is a violation of the contract that the npm CLI presents. As of [email protected], these errors are handled properly in npm-lifecycle, so the additional uninformative crash is no longer doing anything. This commit removes that uninformative crash. This also means that we won't fail _until_ an invalid user config is actually relevant; if someone never runs an install script (or runs with --ignore-scripts), then it's not relevant, so we can move forward anyway.
1 parent a4e2795 commit 769d2e0

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

lib/config/core.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ function Conf (base) {
218218

219219
Conf.prototype.loadPrefix = require('./load-prefix.js')
220220
Conf.prototype.loadCAFile = require('./load-cafile.js')
221-
Conf.prototype.loadUid = require('./load-uid.js')
222221
Conf.prototype.setUser = require('./set-user.js')
223222
Conf.prototype.getCredentialsByURI = require('./get-credentials-by-uri.js')
224223
Conf.prototype.setCredentialsByURI = require('./set-credentials-by-uri.js')
@@ -227,11 +226,8 @@ Conf.prototype.clearCredentialsByURI = require('./clear-credentials-by-uri.js')
227226
Conf.prototype.loadExtras = function (cb) {
228227
this.setUser(function (er) {
229228
if (er) return cb(er)
230-
this.loadUid(function (er) {
231-
if (er) return cb(er)
232-
// Without prefix, nothing will ever work
233-
mkdirp(this.prefix, cb)
234-
}.bind(this))
229+
// Without prefix, nothing will ever work
230+
mkdirp(this.prefix, cb)
235231
}.bind(this))
236232
}
237233

lib/config/load-uid.js

-15
This file was deleted.

lib/utils/error-message.js

+14
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ function errorMessage (er) {
7272
}
7373
break
7474

75+
case 'EUIDLOOKUP':
76+
short.push(['lifecycle', er.message])
77+
detail.push([
78+
'',
79+
[
80+
'',
81+
'Failed to look up the user/group for running scripts.',
82+
'',
83+
'Try again with a different --user or --group settings, or',
84+
'run with --unsafe-perm to execute scripts as root.'
85+
].join('\n')
86+
])
87+
break
88+
7589
case 'ELIFECYCLE':
7690
short.push(['', er.message])
7791
detail.push([

0 commit comments

Comments
 (0)