-
Notifications
You must be signed in to change notification settings - Fork 529
Open
Description
import assert from 'node:assert'
globalThis.addEventListener('unhandledrejection', (e) => {
console.error('unhandled rejection:', e.reason)
})
const asyncFunction = async (name) => {
throw new Error(`this function rejects: ${name}`)
}
export const AssertBased = {
async test(ctrl, env, ctx) {
assert.rejects(async () => asyncFunction('A'))
},
}
export const Manual = {
async test(ctrl, env, ctx) {
const error = await Promise.resolve().then(function () {
return asyncFunction('B')
}).then(function () {
return null
}).catch(function (e) {
return e
})
// console.log('Got this error:', error)
},
}
export const TryCatch = {
async test(ctrl, env, ctx) {
try {
await Promise.resolve('C').then(asyncFunction)
} catch (error) {
// console.log('Got this error:', error)
}
},
}In all these cases, A, B, and C are logged as unhandled rejections, while they are, in fact, handled.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels