(er, npm)
| 4 | const { log } = require('proc-log') |
| 5 | |
| 6 | const 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')}"`, |
no test coverage detected
searching dependent graphs…