mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
feat(core): intercept unhandled promise rejections (#12910)
Provide a programmatic means of intercepting rejected promises without a .catch() handler. Needed for Node compat mode. Also do a first pass at uncaughtException support because they're closely intertwined in Node. It's like that Frank Sinatra song: you can't have one without the other. Stepping stone for #7013.
This commit is contained in:
parent
993a1dd41a
commit
2d830c263b
3 changed files with 271 additions and 37 deletions
26
core/lib.deno_core.d.ts
vendored
26
core/lib.deno_core.d.ts
vendored
|
@ -115,5 +115,31 @@ declare namespace Deno {
|
|||
function setMacrotaskCallback(
|
||||
cb: () => bool,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Set a callback that will be called when a promise without a .catch
|
||||
* handler is rejected. Returns the old handler or undefined.
|
||||
*/
|
||||
function setPromiseRejectCallback(
|
||||
cb: PromiseRejectCallback,
|
||||
): undefined | PromiseRejectCallback;
|
||||
|
||||
export type PromiseRejectCallback = (
|
||||
type: number,
|
||||
promise: Promise,
|
||||
reason: any,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* Set a callback that will be called when an exception isn't caught
|
||||
* by any try/catch handlers. Currently only invoked when the callback
|
||||
* to setPromiseRejectCallback() throws an exception but that is expected
|
||||
* to change in the future. Returns the old handler or undefined.
|
||||
*/
|
||||
function setUncaughtExceptionCallback(
|
||||
cb: UncaughtExceptionCallback,
|
||||
): undefined | UncaughtExceptionCallback;
|
||||
|
||||
export type UncaughtExceptionCallback = (err: any) => void;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue