From eb2998196e63c6b9ba9ebc01d9542a1a06b143f0 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 4 Sep 2023 13:55:32 +0200 Subject: [PATCH] ref(browser): Deprecate top-level `wrap` function (#8927) Deprecate the `wrap` function exported from `@sentry/browser`. This function is documented nowhere, not part of the unified API and afaict not used by any SDKs depending on `@sentry/browser`. --- packages/browser/src/exports.ts | 11 ++++++++++- packages/browser/src/sdk.ts | 5 +++++ packages/browser/test/unit/index.test.ts | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/browser/src/exports.ts b/packages/browser/src/exports.ts index 03533bdbc90d..e9050399e641 100644 --- a/packages/browser/src/exports.ts +++ b/packages/browser/src/exports.ts @@ -63,5 +63,14 @@ export { } from './stack-parsers'; export { eventFromException, eventFromMessage, exceptionFromError } from './eventbuilder'; export { createUserFeedbackEnvelope } from './userfeedback'; -export { defaultIntegrations, forceLoad, init, onLoad, showReportDialog, wrap, captureUserFeedback } from './sdk'; +export { + defaultIntegrations, + forceLoad, + init, + onLoad, + showReportDialog, + captureUserFeedback, + // eslint-disable-next-line deprecation/deprecation + wrap, +} from './sdk'; export { GlobalHandlers, TryCatch, Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations'; diff --git a/packages/browser/src/sdk.ts b/packages/browser/src/sdk.ts index 45fd26c75745..de352d9db154 100644 --- a/packages/browser/src/sdk.ts +++ b/packages/browser/src/sdk.ts @@ -192,10 +192,15 @@ export function onLoad(callback: () => void): void { /** * Wrap code within a try/catch block so the SDK is able to capture errors. * + * @deprecated This function will be removed in v8. + * It is not part of Sentry's official API and it's easily replaceable by using a try/catch block + * and calling Sentry.captureException. + * * @param fn A function to wrap. * * @returns The result of wrapped function call. */ +// TODO(v8): Remove this function // eslint-disable-next-line @typescript-eslint/no-explicit-any export function wrap(fn: (...args: any) => any): any { return internalWrap(fn)(); diff --git a/packages/browser/test/unit/index.test.ts b/packages/browser/test/unit/index.test.ts index 122637ea91d4..95985a2a69d2 100644 --- a/packages/browser/test/unit/index.test.ts +++ b/packages/browser/test/unit/index.test.ts @@ -355,6 +355,7 @@ describe('wrap()', () => { getCurrentHub().bindClient(new BrowserClient(options)); try { + // eslint-disable-next-line deprecation/deprecation wrap(() => { throw new TypeError('mkey'); }); @@ -364,11 +365,13 @@ describe('wrap()', () => { }); it('should return result of a function call', () => { + // eslint-disable-next-line deprecation/deprecation const result = wrap(() => 2); expect(result).toBe(2); }); it('should allow for passing this and arguments through binding', () => { + // eslint-disable-next-line deprecation/deprecation const result = wrap( function (this: unknown, a: string, b: number): unknown[] { return [this, a, b]; @@ -379,6 +382,7 @@ describe('wrap()', () => { expect((result as unknown[])[1]).toBe('b'); expect((result as unknown[])[2]).toBe(42); + // eslint-disable-next-line deprecation/deprecation const result2 = wrap( function (this: { x: number }): number { return this.x;