From 34352e6c24d23a79975f978ee9004c9bd5fa4742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pazgan?= Date: Mon, 27 Apr 2020 19:30:43 +0200 Subject: [PATCH] Fix exception auto collector incorrectly handling promise exceptions (#618) Co-authored-by: Lukasz Pazgan Co-authored-by: Mark Wolff --- AutoCollection/Exceptions.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AutoCollection/Exceptions.ts b/AutoCollection/Exceptions.ts index f4091b5e..21089052 100644 --- a/AutoCollection/Exceptions.ts +++ b/AutoCollection/Exceptions.ts @@ -46,7 +46,7 @@ class AutoCollectExceptions { if (!this._exceptionListenerHandle) { // For scenarios like Promise.reject(), an error won't be passed to the handle. Create a placeholder // error for these scenarios. - var handle = (reThrow: boolean, name?: string, error: Error = new Error(AutoCollectExceptions._FALLBACK_ERROR_MESSAGE)) => { + var handle = (reThrow: boolean, name: string, error: Error = new Error(AutoCollectExceptions._FALLBACK_ERROR_MESSAGE)) => { this._client.trackException({ exception: error }); this._client.flush({ isAppCrashing: true }); // only rethrow when we are the only listener @@ -58,11 +58,11 @@ class AutoCollectExceptions { if (AutoCollectExceptions._canUseUncaughtExceptionMonitor) { // Node.js >= 13.7.0, use uncaughtExceptionMonitor. It handles both promises and exceptions - this._exceptionListenerHandle = handle.bind(this, false); // never rethrows + this._exceptionListenerHandle = handle.bind(this, false, undefined); // never rethrows process.on(AutoCollectExceptions.UNCAUGHT_EXCEPTION_MONITOR_HANDLER_NAME, this._exceptionListenerHandle); } else { this._exceptionListenerHandle = handle.bind(this, true, AutoCollectExceptions.UNCAUGHT_EXCEPTION_HANDLER_NAME); - this._rejectionListenerHandle = handle.bind(this, false); // never rethrows + this._rejectionListenerHandle = handle.bind(this, false, undefined); // never rethrows process.on(AutoCollectExceptions.UNCAUGHT_EXCEPTION_HANDLER_NAME, this._exceptionListenerHandle); process.on(AutoCollectExceptions.UNHANDLED_REJECTION_HANDLER_NAME, this._rejectionListenerHandle); }