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

Function getError

deps/npm/lib/utils/error-message.js:382–447  ·  view source on GitHub ↗
(err, { npm, command, pkg })

Source from the content-addressed store, hash-verified

380}
381
382const getError = (err, { npm, command, pkg }) => {
383 // if we got a command that just shells out to something else, then it will presumably print its own errors and exit with a proper status code if there's a problem.
384 // If we got an error with a code=0, then... something else went wrong along the way, so maybe an npm problem?
385 if (command?.constructor?.isShellout && typeof err.code === 'number' && err.code) {
386 return {
387 exitCode: err.code,
388 suppressError: true,
389 }
390 }
391
392 // XXX: we should stop throwing strings
393 if (typeof err === 'string') {
394 return {
395 exitCode: 1,
396 suppressError: true,
397 summary: [['', err]],
398 }
399 }
400
401 // XXX: we should stop throwing other non-errors
402 if (!(err instanceof Error)) {
403 return {
404 exitCode: 1,
405 suppressError: true,
406 summary: [['weird error', err]],
407 }
408 }
409
410 if (err.code === 'EUNKNOWNCOMMAND') {
411 const suggestions = require('./did-you-mean.js')(pkg, err.command)
412 return {
413 exitCode: 1,
414 suppressError: true,
415 standard: [
416 `Unknown command: "${err.command}"`,
417 suggestions,
418 'To see a list of supported npm commands, run:',
419 ' npm help',
420 ],
421 }
422 }
423
424 // Anything after this is not suppressed and gets more logged information
425
426 // add a code to the error if it doesnt have one and mutate some properties so they have redacted information
427 err.code ??= err.message.match(/^(?:Error: )?(E[A-Z]+)/)?.[1]
428 // this mutates the error and redacts stack/message
429 const { summary, detail, files, json } = errorMessage(err, npm)
430
431 return {
432 err,
433 code: err.code,
434 exitCode: getExitCodeFromError(err) || 1,
435 suppressError: false,
436 summary,
437 detail,
438 files,
439 json,

Callers 4

mainFunction · 0.50
mainFunction · 0.50
execWorkspacesMethod · 0.50
execWorkspacesMethod · 0.50

Calls 6

getExitCodeFromErrorFunction · 0.85
errorMessageFunction · 0.70
matchMethod · 0.65
mapMethod · 0.65
filterMethod · 0.65
requireFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…