Skip to content

Commit

Permalink
feat: show stack-trace of unhandled errors with DEBUG env (#212)
Browse files Browse the repository at this point in the history
Co-authored-by: pooya parsa <pyapar@gmail.com>
  • Loading branch information
tobiasdiez and pi0 committed May 10, 2022
1 parent 9c9fb34 commit b366f3f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/runtime/entries/nitro-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ server.listen(listenAddress, () => {
})
})

process.on('unhandledRejection', err => console.error('[nitro] [dev] [unhandledRejection] ' + err))
process.on('uncaughtException', err => console.error('[nitro] [dev] [uncaughtException] ' + err))
if (process.env.DEBUG) {
process.on('unhandledRejection', err => console.error('[nitro] [dev] [unhandledRejection]', err))
process.on('uncaughtException', err => console.error('[nitro] [dev] [uncaughtException]', err))
} else {
process.on('unhandledRejection', err => console.error('[nitro] [dev] [unhandledRejection] ' + err))
process.on('uncaughtException', err => console.error('[nitro] [dev] [uncaughtException] ' + err))
}
9 changes: 7 additions & 2 deletions src/runtime/entries/nitro-prerenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ import { nitroApp } from '../app'

export const localFetch = nitroApp.localFetch

process.on('unhandledRejection', err => console.error('[nitro] [dev] [unhandledRejection] ' + err))
process.on('uncaughtException', err => console.error('[nitro] [dev] [uncaughtException] ' + err))
if (process.env.DEBUG) {
process.on('unhandledRejection', err => console.error('[nitro] [dev] [unhandledRejection]', err))
process.on('uncaughtException', err => console.error('[nitro] [dev] [uncaughtException]', err))
} else {
process.on('unhandledRejection', err => console.error('[nitro] [dev] [unhandledRejection] ' + err))
process.on('uncaughtException', err => console.error('[nitro] [dev] [uncaughtException] ' + err))
}
9 changes: 7 additions & 2 deletions src/runtime/entries/node-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ server.listen(port, hostname, (err) => {
console.log(`Listening on ${protocol}://${hostname}:${port}${useRuntimeConfig().app.baseURL}`)
})

process.on('unhandledRejection', err => console.error('[nitro] [dev] [unhandledRejection] ' + err))
process.on('uncaughtException', err => console.error('[nitro] [dev] [uncaughtException] ' + err))
if (process.env.DEBUG) {
process.on('unhandledRejection', err => console.error('[nitro] [dev] [unhandledRejection]', err))
process.on('uncaughtException', err => console.error('[nitro] [dev] [uncaughtException]', err))
} else {
process.on('unhandledRejection', err => console.error('[nitro] [dev] [unhandledRejection] ' + err))
process.on('uncaughtException', err => console.error('[nitro] [dev] [uncaughtException] ' + err))
}

export default {}
4 changes: 2 additions & 2 deletions src/runtime/entries/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { nitroApp } from '../app'

export const handler = nitroApp.h3App.nodeHandler

process.on('unhandledRejection', err => console.error('[nitro] [dev] [unhandledRejection] ' + err))
process.on('uncaughtException', err => console.error('[nitro] [dev] [uncaughtException] ' + err))
process.on('unhandledRejection', err => console.error('[nitro] [dev] [unhandledRejection]', err))
process.on('uncaughtException', err => console.error('[nitro] [dev] [uncaughtException]', err))

0 comments on commit b366f3f

Please sign in to comment.