Skip to content

Commit

Permalink
Fix exception auto collector incorrectly handling promise exceptions (#…
Browse files Browse the repository at this point in the history
…618)

Co-authored-by: Lukasz Pazgan <lukasz.pazgan@motorolasolutions.com>
Co-authored-by: Mark Wolff <marwolff@microsoft.com>
  • Loading branch information
3 people committed Apr 27, 2020
1 parent 2855952 commit 34352e6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions AutoCollection/Exceptions.ts
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down

0 comments on commit 34352e6

Please sign in to comment.