Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 769d2e0

Browse filesBrowse 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 npm-lifecycle@3.1.3, 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 npm-lifecycle@3.1.3, 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
Copy full SHA for 769d2e0

File tree

Expand file treeCollapse file tree

3 files changed

+16
-21
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-21
lines changed

‎lib/config/core.js

Copy file name to clipboardExpand all lines: lib/config/core.js
+2-6Lines changed: 2 additions & 6 deletions
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

Copy file name to clipboardExpand all lines: lib/config/load-uid.js
-15Lines changed: 0 additions & 15 deletions
This file was deleted.

‎lib/utils/error-message.js

Copy file name to clipboardExpand all lines: lib/utils/error-message.js
+14Lines changed: 14 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.