-
-
Notifications
You must be signed in to change notification settings - Fork 792
Open
Description
I have a custom logger class which uses Ink.
If I hit an exception anywhere in my application, the parent process immediately exits and stops Ink from going through any final render cycles that would result in logs being printed.
If I put a timeout for 10ms directly before throwing an error, Ink finishes as expected. But I don't always know where errors are going to occur.
This is the best I've come up with in my logger class:
private setupExitHandler() {
const flush = async () => {
// give Ink a bit of time to get one or two additional renders in
await new Promise(resolve => setTimeout(resolve, 100))
}
process.on('uncaughtException', async error => {
await flush()
console.error(`${error.stack} ${error.message}`)
})
process.on('unhandledRejection', async reason => {
await flush()
const error = reason instanceof Error ? reason : new Error(String(reason))
console.error(`${error.stack} ${error.message}`)
})
}Is there a canonical/better way to do this?
Metadata
Metadata
Assignees
Labels
No labels