"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/utils/error-message.js" (11 Apr 2017, 9580 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict'
    2 var npm = require('../npm.js')
    3 var util = require('util')
    4 var nameValidator = require('validate-npm-package-name')
    5 
    6 module.exports = errorMessage
    7 
    8 function errorMessage (er) {
    9   var short = []
   10   var detail = []
   11   if (er.optional) {
   12     short.push(['optional', 'Skipping failed optional dependency ' + er.optional + ':'])
   13   }
   14   switch (er.code) {
   15     case 'ECONNREFUSED':
   16       short.push(['', er])
   17       detail.push([
   18         '',
   19         [
   20           '\nIf you are behind a proxy, please make sure that the',
   21           "'proxy' config is set properly.  See: 'npm help config'"
   22         ].join('\n')
   23       ])
   24       break
   25 
   26     case 'EACCES':
   27     case 'EPERM':
   28       short.push(['', er])
   29       detail.push(['', ['\nPlease try running this command again as root/Administrator.'
   30                 ].join('\n')])
   31       break
   32 
   33     case 'ELIFECYCLE':
   34       short.push(['', er.message])
   35       detail.push([
   36         '',
   37         [
   38           '',
   39           'Failed at the ' + er.pkgid + ' ' + er.stage + " script '" + er.script + "'.",
   40           'Make sure you have the latest version of node.js and npm installed.',
   41           'If you do, this is most likely a problem with the ' + er.pkgname + ' package,',
   42           'not with npm itself.',
   43           'Tell the author that this fails on your system:',
   44           '    ' + er.script,
   45           'You can get information on how to open an issue for this project with:',
   46           '    npm bugs ' + er.pkgname,
   47           'Or if that isn\'t available, you can get their info via:',
   48           '    npm owner ls ' + er.pkgname,
   49           'There is likely additional logging output above.'
   50         ].join('\n')]
   51       )
   52       break
   53 
   54     case 'ENOGIT':
   55       short.push(['', er.message])
   56       detail.push([
   57         '',
   58         [
   59           '',
   60           'Failed using git.',
   61           'This is most likely not a problem with npm itself.',
   62           'Please check if you have git installed and in your PATH.'
   63         ].join('\n')
   64       ])
   65       break
   66 
   67     case 'EJSONPARSE':
   68       short.push(['', er.message])
   69       short.push(['', 'File: ' + er.file])
   70       detail.push([
   71         '',
   72         [
   73           'Failed to parse package.json data.',
   74           'package.json must be actual JSON, not just JavaScript.',
   75           '',
   76           'This is not a bug in npm.',
   77           'Tell the package author to fix their package.json file.'
   78         ].join('\n'),
   79         'JSON.parse'
   80       ])
   81       break
   82 
   83     // TODO(isaacs)
   84     // Add a special case here for E401 and E403 explaining auth issues?
   85 
   86     case 'E404':
   87       // There's no need to have 404 in the message as well.
   88       var msg = er.message.replace(/^404\s+/, '')
   89       short.push(['404', msg])
   90       if (er.pkgid && er.pkgid !== '-') {
   91         detail.push(['404', ''])
   92         detail.push(['404', '', "'" + er.pkgid + "' is not in the npm registry."])
   93 
   94         var valResult = nameValidator(er.pkgid)
   95 
   96         if (valResult.validForNewPackages) {
   97           detail.push(['404', 'You should bug the author to publish it (or use the name yourself!)'])
   98         } else {
   99           detail.push(['404', 'Your package name is not valid, because', ''])
  100 
  101           var errorsArray = (valResult.errors || []).concat(valResult.warnings || [])
  102           errorsArray.forEach(function (item, idx) {
  103             detail.push(['404', ' ' + (idx + 1) + '. ' + item])
  104           })
  105         }
  106 
  107         if (er.parent) {
  108           detail.push(['404', "It was specified as a dependency of '" + er.parent + "'"])
  109         }
  110         detail.push(['404', '\nNote that you can also install from a'])
  111         detail.push(['404', 'tarball, folder, http url, or git url.'])
  112       }
  113       break
  114 
  115     case 'EPUBLISHCONFLICT':
  116       short.push(['publish fail', 'Cannot publish over existing version.'])
  117       detail.push(['publish fail', "Update the 'version' field in package.json and try again."])
  118       detail.push(['publish fail', ''])
  119       detail.push(['publish fail', 'To automatically increment version numbers, see:'])
  120       detail.push(['publish fail', '    npm help version'])
  121       break
  122 
  123     case 'EISGIT':
  124       short.push(['git', er.message])
  125       short.push(['git', '    ' + er.path])
  126       detail.push([
  127         'git',
  128         [
  129           'Refusing to remove it. Update manually,',
  130           'or move it out of the way first.'
  131         ].join('\n')
  132       ])
  133       break
  134 
  135     case 'ECYCLE':
  136       short.push([
  137         'cycle',
  138         [
  139           er.message,
  140           'While installing: ' + er.pkgid
  141         ].join('\n')
  142       ])
  143       detail.push([
  144         'cycle',
  145         [
  146           'Found a pathological dependency case that npm cannot solve.',
  147           'Please report this to the package author.'
  148         ].join('\n')
  149       ])
  150       break
  151 
  152     case 'EBADPLATFORM':
  153       short.push([
  154         'notsup',
  155         [
  156           'Not compatible with your operating system or architecture: ' + er.pkgid
  157         ].join('\n')
  158       ])
  159       detail.push([
  160         'notsup',
  161         [
  162           'Valid OS:    ' + (er.os.join ? er.os.join(',') : util.inspect(er.os)),
  163           'Valid Arch:  ' + (er.cpu.join ? er.cpu.join(',') : util.inspect(er.cpu)),
  164           'Actual OS:   ' + process.platform,
  165           'Actual Arch: ' + process.arch
  166         ].join('\n')
  167       ])
  168       break
  169 
  170     case 'EEXIST':
  171       short.push(['', er.message])
  172       short.push(['', 'File exists: ' + er.path])
  173       detail.push(['', 'Move it away, and try again.'])
  174       break
  175 
  176     case 'ENEEDAUTH':
  177       short.push(['need auth', er.message])
  178       detail.push(['need auth', 'You need to authorize this machine using `npm adduser`'])
  179       break
  180 
  181     case 'ECONNRESET':
  182     case 'ENOTFOUND':
  183     case 'ETIMEDOUT':
  184     case 'EAI_FAIL':
  185       short.push(['network', er.message])
  186       detail.push([
  187         'network',
  188         [
  189           'This is most likely not a problem with npm itself',
  190           'and is related to network connectivity.',
  191           'In most cases you are behind a proxy or have bad network settings.',
  192           '\nIf you are behind a proxy, please make sure that the',
  193           "'proxy' config is set properly.  See: 'npm help config'"
  194         ].join('\n')
  195       ])
  196       break
  197 
  198     case 'ENOPACKAGEJSON':
  199       short.push(['package.json', er.message])
  200       detail.push([
  201         'package.json',
  202         [
  203           'This is most likely not a problem with npm itself.',
  204           "npm can't find a package.json file in your current directory."
  205         ].join('\n')
  206       ])
  207       break
  208 
  209     case 'ETARGET':
  210       short.push(['notarget', er.message])
  211       msg = [
  212         'This is most likely not a problem with npm itself.',
  213         'In most cases you or one of your dependencies are requesting',
  214         "a package version that doesn't exist."
  215       ]
  216       if (er.parent) {
  217         msg.push("\nIt was specified as a dependency of '" + er.parent + "'\n")
  218       }
  219       detail.push(['notarget', msg.join('\n')])
  220       break
  221 
  222     case 'ENOTSUP':
  223       if (er.required) {
  224         short.push(['notsup', er.message])
  225         short.push(['notsup', 'Not compatible with your version of node/npm: ' + er.pkgid])
  226         detail.push([
  227           'notsup',
  228           [
  229             'Not compatible with your version of node/npm: ' + er.pkgid,
  230             'Required: ' + JSON.stringify(er.required),
  231             'Actual:   ' + JSON.stringify({
  232               npm: npm.version,
  233               node: npm.config.get('node-version')
  234             })
  235           ].join('\n')
  236         ])
  237         break
  238       } // else passthrough
  239       /*eslint no-fallthrough:0*/
  240 
  241     case 'ENOSPC':
  242       short.push(['nospc', er.message])
  243       detail.push([
  244         'nospc',
  245         [
  246           'This is most likely not a problem with npm itself',
  247           'and is related to insufficient space on your system.'
  248         ].join('\n')
  249       ])
  250       break
  251 
  252     case 'EROFS':
  253       short.push(['rofs', er.message])
  254       detail.push([
  255         'rofs',
  256         [
  257           'This is most likely not a problem with npm itself',
  258           'and is related to the file system being read-only.',
  259           '\nOften virtualized file systems, or other file systems',
  260           "that don't support symlinks, give this error."
  261         ].join('\n')
  262       ])
  263       break
  264 
  265     case 'ENOENT':
  266       short.push(['enoent', er.message])
  267       detail.push([
  268         'enoent',
  269         [
  270           er.message,
  271           'This is most likely not a problem with npm itself',
  272           'and is related to npm not being able to find a file.',
  273           er.file ? "\nCheck if the file '" + er.file + "' is present." : ''
  274         ].join('\n')
  275       ])
  276       break
  277 
  278     case 'EMISSINGARG':
  279     case 'EUNKNOWNTYPE':
  280     case 'EINVALIDTYPE':
  281     case 'ETOOMANYARGS':
  282       short.push(['typeerror', er.stack])
  283       detail.push([
  284         'typeerror',
  285         [
  286           'This is an error with npm itself. Please report this error at:',
  287           '    <http://github.com/npm/npm/issues>'
  288         ].join('\n')
  289       ])
  290       break
  291 
  292     case 'EISDIR':
  293       short.push(['eisdir', er.message])
  294       detail.push([
  295         'eisdir',
  296         [
  297           'This is most likely not a problem with npm itself',
  298           'and is related to npm not being able to find a package.json in',
  299           'a package you are trying to install.'
  300         ].join('\n')
  301       ])
  302       break
  303 
  304     default:
  305       short.push(['', er.message || er])
  306       detail.push([
  307         '',
  308         [
  309           '',
  310           'If you need help, you may report this error at:',
  311           '    <https://github.com/npm/npm/issues>'
  312         ].join('\n')
  313       ])
  314       break
  315   }
  316   return {summary: short, detail: detail}
  317 }