MCPcopy Index your code
hub / github.com/nodejs/node / errorMessage

Function errorMessage

deps/npm/lib/utils/error-message.js:6–372  ·  view source on GitHub ↗
(er, npm)

Source from the content-addressed store, hash-verified

4const { log } = require('proc-log')
5
6const errorMessage = (er, npm) => {
7 const summary = []
8 const detail = []
9 const files = []
10 let json
11
12 er.message &&= replaceInfo(er.message)
13 er.stack &&= replaceInfo(er.stack)
14
15 switch (er.code) {
16 case 'ERESOLVE': {
17 const { report } = require('./explain-eresolve.js')
18 summary.push(['ERESOLVE', er.message])
19 detail.push(['', ''])
20 // XXX(display): error messages are logged so we use the logColor since that is based on stderr.
21 // This should be handled solely by the display layer so it could also be printed to stdout if necessary.
22 const { explanation, file } = report(er, npm.logChalk, npm.noColorChalk)
23 detail.push(['', explanation])
24 files.push(['eresolve-report.txt', file])
25 break
26 }
27
28 case 'ENOLOCK': {
29 const cmd = npm.command || ''
30 summary.push([cmd, 'This command requires an existing lockfile.'])
31 detail.push([cmd, 'Try creating one first with: npm i --package-lock-only'])
32 detail.push([cmd, `Original error: ${er.message}`])
33 break
34 }
35
36 case 'ENOAUDIT':
37 summary.push(['audit', er.message])
38 break
39
40 case 'ECONNREFUSED':
41 summary.push(['', er])
42 detail.push(['', [
43 '',
44 `If you are behind a proxy, please make sure that the 'proxy' config is set properly. See: 'npm help config'`,
45 ].join('\n')])
46 break
47
48 case 'EACCES':
49 case 'EPERM': {
50 const isCachePath =
51 typeof er.path === 'string' && npm.loaded && er.path.startsWith(npm.config.get('cache'))
52 const isCacheDest =
53 typeof er.dest === 'string' && npm.loaded && er.dest.startsWith(npm.config.get('cache'))
54
55 if (process.platform !== 'win32' && (isCachePath || isCacheDest)) {
56 // user probably doesn't need this, but still add it to the debug log
57 log.verbose(er.stack)
58 summary.push(['', [
59 '',
60 'Your cache folder contains root-owned files, due to a bug in previous versions of npm which has since been addressed.',
61 '',
62 'To permanently fix this problem, please run:',
63 ` sudo chown -R ${process.getuid()}:${process.getgid()} "${npm.config.get('cache')}"`,

Callers 4

getErrorFunction · 0.70
#logConsoleErrorMethod · 0.50
error-message.jsFile · 0.50
runTestFunction · 0.50

Calls 15

verboseMethod · 0.80
includesMethod · 0.80
reportFunction · 0.70
getMethod · 0.65
mapMethod · 0.65
forEachMethod · 0.65
requireFunction · 0.50
resolveFunction · 0.50
formatFunction · 0.50
pushMethod · 0.45
joinMethod · 0.45
readFileSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…