From d1ec342e623e69d6601fe6322ae533e354aeda96 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 22 Nov 2022 13:26:46 +0100 Subject: [PATCH] fix(core): Add guard against scope.getAttachments --- packages/core/src/baseclient.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/src/baseclient.ts b/packages/core/src/baseclient.ts index 683420217613..465d1c95b6f6 100644 --- a/packages/core/src/baseclient.ts +++ b/packages/core/src/baseclient.ts @@ -437,7 +437,12 @@ export abstract class BaseClient implements Client { // This should be the last thing called, since we want that // {@link Hub.addEventProcessor} gets the finished prepared event. - if (finalScope) { + // + // We need to check for the existence of `finalScope.getAttachments` + // because `getAttachments` can be undefined if users are using an older version + // of `@sentry/core` that does not have the `getAttachments` method. + // See: https://github.com/getsentry/sentry-javascript/issues/5229 + if (finalScope && finalScope.getAttachments) { // Collect attachments from the hint and scope const attachments = [...(hint.attachments || []), ...finalScope.getAttachments()];