Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exit-handler): always warn if not called #3561

Merged
merged 1 commit into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ process.on('exit', code => {

if (!code)
npm.log.info('ok')
else {
else
npm.log.verbose('code', code)
if (!exitHandlerCalled) {
npm.log.error('', 'Exit handler never called!')
console.error('')
npm.log.error('', 'This is an error with npm itself. Please report this error at:')
npm.log.error('', ' <https://github.com/npm/cli/issues>')
// TODO this doesn't have an npm.config.loaded guard
writeLogFile()
}

if (!exitHandlerCalled) {
process.exitCode = code || 1
npm.log.error('', 'Exit handler never called!')
console.error('')
npm.log.error('', 'This is an error with npm itself. Please report this error at:')
npm.log.error('', ' <https://github.com/npm/cli/issues>')
// TODO this doesn't have an npm.config.loaded guard
writeLogFile()
}
// In timing mode we always write the log file
if (npm.config.loaded && npm.config.get('timing') && !wroteLogFile)
Expand Down
11 changes: 5 additions & 6 deletions test/lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,14 @@ t.test('defaults to log error msg if stack is missing', (t) => {
t.end()
})

t.test('exits cleanly when emitting exit event', (t) => {
t.plan(1)
t.test('exits uncleanly when only emitting exit event', (t) => {
t.plan(2)

npm.log.level = 'silent'
process.emit('exit')
t.match(
npm.log.record.find(r => r.level === 'info'),
{ prefix: 'ok', message: '' }
)
const logData = fs.readFileSync(logFile, 'utf8')
t.match(logData, 'Exit handler never called!')
t.match(process.exitCode, 1, 'exitCode coerced to 1')
t.end()
})

Expand Down