Skip to content

Commit 4a11e32

Browse files
committed
ref(browser): Deprecate top-level wrap function
1 parent 91c48c9 commit 4a11e32

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

packages/browser/src/exports.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,14 @@ export {
6363
} from './stack-parsers';
6464
export { eventFromException, eventFromMessage, exceptionFromError } from './eventbuilder';
6565
export { createUserFeedbackEnvelope } from './userfeedback';
66-
export { defaultIntegrations, forceLoad, init, onLoad, showReportDialog, wrap, captureUserFeedback } from './sdk';
66+
export {
67+
defaultIntegrations,
68+
forceLoad,
69+
init,
70+
onLoad,
71+
showReportDialog,
72+
captureUserFeedback,
73+
// eslint-disable-next-line deprecation/deprecation
74+
wrap,
75+
} from './sdk';
6776
export { GlobalHandlers, TryCatch, Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations';

packages/browser/src/sdk.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,15 @@ export function onLoad(callback: () => void): void {
192192
/**
193193
* Wrap code within a try/catch block so the SDK is able to capture errors.
194194
*
195+
* @deprecated This function will be removed in v8.
196+
* It is not part of Sentry's official API and it's easily replaceable by using a try/catch block
197+
* and calling Sentry.captureException.
198+
*
195199
* @param fn A function to wrap.
196200
*
197201
* @returns The result of wrapped function call.
198202
*/
203+
// TODO(v8): Remove this function
199204
// eslint-disable-next-line @typescript-eslint/no-explicit-any
200205
export function wrap(fn: (...args: any) => any): any {
201206
return internalWrap(fn)();

packages/browser/test/unit/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ describe('wrap()', () => {
355355
getCurrentHub().bindClient(new BrowserClient(options));
356356

357357
try {
358+
// eslint-disable-next-line deprecation/deprecation
358359
wrap(() => {
359360
throw new TypeError('mkey');
360361
});
@@ -364,11 +365,13 @@ describe('wrap()', () => {
364365
});
365366

366367
it('should return result of a function call', () => {
368+
// eslint-disable-next-line deprecation/deprecation
367369
const result = wrap(() => 2);
368370
expect(result).toBe(2);
369371
});
370372

371373
it('should allow for passing this and arguments through binding', () => {
374+
// eslint-disable-next-line deprecation/deprecation
372375
const result = wrap(
373376
function (this: unknown, a: string, b: number): unknown[] {
374377
return [this, a, b];
@@ -379,6 +382,7 @@ describe('wrap()', () => {
379382
expect((result as unknown[])[1]).toBe('b');
380383
expect((result as unknown[])[2]).toBe(42);
381384

385+
// eslint-disable-next-line deprecation/deprecation
382386
const result2 = wrap(
383387
function (this: { x: number }): number {
384388
return this.x;

0 commit comments

Comments
 (0)