From 2d830c263b0a3519c7fb75199a6ad1b8f10d2b51 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 28 Nov 2021 00:46:12 +0100 Subject: 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. --- core/lib.deno_core.d.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'core/lib.deno_core.d.ts') diff --git a/core/lib.deno_core.d.ts b/core/lib.deno_core.d.ts index 59b2df542..240284c88 100644 --- a/core/lib.deno_core.d.ts +++ b/core/lib.deno_core.d.ts @@ -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; } } -- cgit v1.2.3