|
2 | 2 | var npm = require('../npm.js')
|
3 | 3 | var util = require('util')
|
4 | 4 | var nameValidator = require('validate-npm-package-name')
|
| 5 | +var npmlog = require('npmlog') |
5 | 6 |
|
6 | 7 | module.exports = errorMessage
|
7 | 8 |
|
@@ -33,18 +34,42 @@ function errorMessage (er) {
|
33 | 34 |
|
34 | 35 | case 'EACCES':
|
35 | 36 | case 'EPERM':
|
36 |
| - short.push(['', er]) |
37 |
| - detail.push([ |
38 |
| - '', |
39 |
| - [ |
40 |
| - '\nThe operation was rejected by your operating system.', |
41 |
| - (process.platform === 'win32' |
42 |
| - ? 'It\'s possible that the file was already in use (by a text editor or antivirus),\nor that you lack permissions to access it.' |
43 |
| - : 'It is likely you do not have the permissions to access this file as the current user'), |
44 |
| - '\nIf you believe this might be a permissions issue, please double-check the', |
45 |
| - 'permissions of the file and its containing directories, or try running', |
46 |
| - 'the command again as root/Administrator (though this is not recommended).' |
47 |
| - ].join('\n')]) |
| 37 | + const isCachePath = typeof er.path === 'string' && |
| 38 | + er.path.startsWith(npm.config.get('cache')) |
| 39 | + const isCacheDest = typeof er.dest === 'string' && |
| 40 | + er.dest.startsWith(npm.config.get('cache')) |
| 41 | + |
| 42 | + const isWindows = process.platform === 'win32' |
| 43 | + |
| 44 | + if (!isWindows && (isCachePath || isCacheDest)) { |
| 45 | + // user probably doesn't need this, but still add it to the debug log |
| 46 | + npmlog.verbose(er.stack) |
| 47 | + short.push([ |
| 48 | + '', |
| 49 | + [ |
| 50 | + '', |
| 51 | + 'Your cache folder contains root-owned files, due to a bug in', |
| 52 | + 'previous versions of npm which has since been addressed.', |
| 53 | + '', |
| 54 | + 'To permanently fix this problem, please run:', |
| 55 | + ` sudo chown -R ${process.getuid()}:${process.getgid()} ${JSON.stringify(npm.config.get('cache'))}` |
| 56 | + ].join('\n') |
| 57 | + ]) |
| 58 | + } else { |
| 59 | + short.push(['', er]) |
| 60 | + detail.push([ |
| 61 | + '', |
| 62 | + [ |
| 63 | + '\nThe operation was rejected by your operating system.', |
| 64 | + (process.platform === 'win32' |
| 65 | + ? 'It\'s possible that the file was already in use (by a text editor or antivirus),\n' + |
| 66 | + 'or that you lack permissions to access it.' |
| 67 | + : 'It is likely you do not have the permissions to access this file as the current user'), |
| 68 | + '\nIf you believe this might be a permissions issue, please double-check the', |
| 69 | + 'permissions of the file and its containing directories, or try running', |
| 70 | + 'the command again as root/Administrator.' |
| 71 | + ].join('\n')]) |
| 72 | + } |
48 | 73 | break
|
49 | 74 |
|
50 | 75 | case 'ELIFECYCLE':
|
|
0 commit comments