Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2021-02-20 07:39:12 +0300
committerisaacs <i@izs.me>2021-02-22 23:30:12 +0300
commit4e58274ed0fd2dd29d3c8d6c7c47f37a37dc0f0f (patch)
treea3e88314ceb246257252307985846a926e839872 /lib
parentbe9f1525587d70c909da88b996220b374583d42a (diff)
Do not print error banner for shell proxy commands
There are a few commands (exec, run-script, and the run-script proxies) where essentially npm is acting like a very fancy shell. It is peculiar and noisy for npm to print a verbose error banner at the end of these commands, since presumably the command itself already did whatever it had to do to report the error appropriately. For example, `npm test` runs a test script, usually outputting test results. Having npm then tell me that my tests failed with exit status 1 and print a debug log, is unnecessary and unwanted. When the error encountered for these commands does not have a non-zero numeric 'code', then we still print the standard npm error reporting messages, because presumably something went wrong OTHER than a process exiting with a non-zero status code. PR-URL: https://github.com/npm/cli/pull/2742 Credit: @isaacs Close: #2742 Reviewed-by: @nlf
Diffstat (limited to 'lib')
-rw-r--r--lib/npm.js5
-rw-r--r--lib/utils/cmd-list.js14
-rw-r--r--lib/utils/error-handler.js14
3 files changed, 30 insertions, 3 deletions
diff --git a/lib/npm.js b/lib/npm.js
index 40aa9bbd9..85dc67a78 100644
--- a/lib/npm.js
+++ b/lib/npm.js
@@ -49,6 +49,7 @@ const makeCmd = cmd => {
}
const { types, defaults, shorthands } = require('./utils/config.js')
+const { shellouts } = require('./utils/cmd-list.js')
let warnedNonDashArg = false
const _runCmd = Symbol('_runCmd')
@@ -81,6 +82,10 @@ const npm = module.exports = new class extends EventEmitter {
this.updateNotification = null
}
+ get shelloutCommands () {
+ return shellouts
+ }
+
deref (c) {
return deref(c)
}
diff --git a/lib/utils/cmd-list.js b/lib/utils/cmd-list.js
index 4e088c12d..336e4dd54 100644
--- a/lib/utils/cmd-list.js
+++ b/lib/utils/cmd-list.js
@@ -136,10 +136,24 @@ const cmdList = [
]
const plumbing = ['birthday', 'help-search']
+
+// these commands just shell out to something else or handle the
+// error themselves, so it's confusing and weird to write out
+// our full error log banner when they exit non-zero
+const shellouts = [
+ 'exec',
+ 'run-script',
+ 'test',
+ 'start',
+ 'stop',
+ 'restart',
+]
+
module.exports = {
aliases: Object.assign({}, shorthands, affordances),
shorthands,
affordances,
cmdList,
plumbing,
+ shellouts,
}
diff --git a/lib/utils/error-handler.js b/lib/utils/error-handler.js
index f9685c91d..1fc31df44 100644
--- a/lib/utils/error-handler.js
+++ b/lib/utils/error-handler.js
@@ -105,8 +105,7 @@ const exit = (code, noLog) => {
if (code && !noLog)
writeLogFile()
- else
- reallyExit()
+ reallyExit()
}
const errorHandler = (er) => {
@@ -130,7 +129,16 @@ const errorHandler = (er) => {
cbCalled = true
if (!er)
return exit(0)
- if (typeof er === 'string') {
+
+ // 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. If we got an error with a code=0, then...
+ // something else went wrong along the way, so maybe an npm problem?
+ const isShellout = npm.shelloutCommands.includes(npm.command)
+ const quietShellout = isShellout && typeof er.code === 'number' && er.code
+ if (quietShellout)
+ return exit(er.code, true)
+ else if (typeof er === 'string') {
log.error('', er)
return exit(1, true)
} else if (!(er instanceof Error)) {