Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
prevent logging disaster while terminating due to exceptions
  • Loading branch information
joao-paulo-parity committed Sep 2, 2021
commit b2891bf7cc8f9db7b5f105e689b85430ad620b3a
29 changes: 23 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,30 @@ var { benchBranch, benchmarkRuntime } = require("./bench")
const githubCommentLimitLength = 65536
const githubCommentLimitTruncateMessage = "<truncated>..."

let isTerminating = false
let appFatalLogger = undefined

for (const event of ["uncaughtException", "unhandledRejection"]) {
process.on(event, function (error, origin) {
if (isTerminating) {
return
}
isTerminating = true

try {
if (appFatalLogger) {
appFatalLogger({ event, error, origin })
}
} catch (error) {
console.error({ level: "error", event, error, origin, exception })
}

process.exit(1)
})
}

module.exports = (app) => {
for (const event of ["uncaughtException", "unhandledRejection"]) {
process.on(event, function (error, origin) {
app.log.fatal({ event, error, origin })
process.exit(1)
})
}
appFatalLogger = app.log.fatal

const baseBranch = process.env.BASE_BRANCH || "master"
app.log.debug(`base branch: ${baseBranch}`)
Expand Down