From fea5a3fdb867895164cb6a8a7d5d7e46f2060436 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Wed, 3 May 2023 15:06:36 +0000 Subject: [PATCH] sentry: Always capture an Error, rather than a string. We pass the original exception down as the `cause`, if present. This makes Sentry properly capture the callstack. --- web/src/blueslip.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/web/src/blueslip.ts b/web/src/blueslip.ts index 56e16bfee9..71b2d3f8bd 100644 --- a/web/src/blueslip.ts +++ b/web/src/blueslip.ts @@ -102,19 +102,14 @@ export function error( more_info?: object | undefined, original_error?: unknown | undefined, ): void { - // original_error could be of any type, because you can "raise" - // any type -- something we do see in practice with the error - // object being "dead": https://github.com/zulip/zulip/issues/18374 - let exception: string | Error = msg; - if (original_error !== undefined && original_error instanceof Error) { - original_error.message = msg; - exception = original_error; - } - // Log the Sentry error before the console warning, so we don't // end up with a doubled message in the Sentry logs. Sentry.setContext("more_info", more_info === undefined ? null : more_info); - Sentry.getCurrentHub().captureException(exception); + + // Note that original_error could be of any type, because you can "raise" + // any type -- something we do see in practice with the error + // object being "dead": https://github.com/zulip/zulip/issues/18374 + Sentry.getCurrentHub().captureException(new Error(msg, {cause: original_error})); const args = build_arg_list(msg, more_info); logger.error(...args);