Skip to content

Commit

Permalink
fix(exitHandler): write code to logfile
Browse files Browse the repository at this point in the history
This moves the logging of the exit code to before the logfile is
written, when the exit handler was not called.  This will ensure that
the code shows up in the debug logs.
  • Loading branch information
wraithgar committed Jun 25, 2021
1 parent cf55fe0 commit 8ab989b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ process.on('exit', code => {
if (!code)
log.info('ok')
else {
log.verbose('code', code)
if (!exitHandlerCalled) {
log.error('', 'Exit handler never called!')
console.error('')
Expand All @@ -66,7 +67,6 @@ process.on('exit', code => {
// TODO this doesn't have an npm.config.loaded guard
writeLogFile()
}
log.verbose('code', code)
}
// In timing mode we always write the log file
if (npm.config && npm.config.loaded && npm.config.get('timing') && !wroteLogFile)
Expand Down
23 changes: 11 additions & 12 deletions tap-snapshots/test/lib/utils/exit-handler.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
*/
'use strict'
exports[`test/lib/utils/exit-handler.js TAP handles unknown error > should have expected log contents for unknown error 1`] = `
0 verbose code 1
1 error foo A complete log of this run can be found in:
1 error foo {CWD}/test/lib/utils/tap-testdir-exit-handler/_logs/expecteddate-debug.log
2 verbose stack Error: ERROR
3 verbose cwd {CWD}
4 verbose Foo 1.0.0
5 verbose argv "/node" "{CWD}/test/lib/utils/exit-handler.js"
6 verbose node v1.0.0
7 verbose npm v1.0.0
8 error foo code ERROR
0 error foo A complete log of this run can be found in:
0 error foo {CWD}/test/lib/utils/tap-testdir-exit-handler/_logs/expecteddate-debug.log
1 verbose stack Error: ERROR
2 verbose cwd {CWD}
3 verbose Foo 1.0.0
4 verbose argv "/node" "{CWD}/test/lib/utils/exit-handler.js"
5 verbose node v1.0.0
6 verbose npm v1.0.0
7 error foo code ERROR
8 error foo ERR ERROR
9 error foo ERR ERROR
10 error foo ERR ERROR
11 verbose exit 1
10 verbose exit 1
`

0 comments on commit 8ab989b

Please sign in to comment.