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/utils
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2020-08-29 00:13:43 +0300
committerRuy Adorno <ruyadorno@hotmail.com>2020-09-01 22:05:41 +0300
commit2d1af0264b0c233b96cec2bae024b3abcd049b16 (patch)
tree6dd9b6fb8202d003d7972becdb79c9f09c7a9967 /lib/utils
parent01d37aee3a77d784530dbe28f4c8ebd940f7e261 (diff)
test: add lib/utils/error-handler.js tests
Add unit tests to `lib/utils/error-handler.js`, these are very special since the module handles some internal state through variables which are not exposed and binds itself to multiple global `process` events. Also two minor tweaks/fixes to the original implementation: - Refactored unused param in `reallyExit()` - Fixed String.prototype.match group capture usage PR-URL: https://github.com/npm/cli/pull/1742 Credit: @ruyadorno Close: #1742 Reviewed-by: @isaacs
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/error-handler.js10
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/utils/error-handler.js b/lib/utils/error-handler.js
index f713bf021..16abcd67c 100644
--- a/lib/utils/error-handler.js
+++ b/lib/utils/error-handler.js
@@ -90,9 +90,7 @@ const exit = (code, noLog) => {
log.verbose('exit', code)
if (log.level === 'silent') noLog = true
- const reallyExit = (er) => {
- if (er && !code) code = typeof er.errno === 'number' ? er.errno : 1
-
+ const reallyExit = () => {
itWorked = !code
// Exit directly -- nothing in the CLI should still be running in the
@@ -141,9 +139,9 @@ const errorHandler = (er) => {
return exit(1, true)
}
- const m = er.code || er.message.match(/^(?:Error: )?(E[A-Z]+)/)
- if (m && !er.code) {
- er.code = m
+ if (!er.code) {
+ const matchErrorCode = er.message.match(/^(?:Error: )?(E[A-Z]+)/)
+ er.code = matchErrorCode && matchErrorCode[1]
}
for (const k of ['type', 'stack', 'statusCode', 'pkgid']) {