Skip to content

Commit

Permalink
feat(v8/browser): Remove deprecated wrap export (#11127)
Browse files Browse the repository at this point in the history
In #8927 we
deprecated and removed the `wrap` method.

This PR removes the deprecated export from v8.
  • Loading branch information
AbhiPrasad committed Mar 18, 2024
1 parent 7eed1ef commit 799dab0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 85 deletions.
7 changes: 6 additions & 1 deletion MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,12 @@ interface Transport {

### Browser SDK (Browser, React, Vue, Angular, Ember, etc.)

Removed top-level exports: `Offline`, `makeXHRTransport`, `BrowserTracing`
Removed top-level exports: `Offline`, `makeXHRTransport`, `BrowserTracing`, `wrap`

- [Removal of the `BrowserTracing` integration](./MIGRATION.md#removal-of-the-browsertracing-integration)
- [Removal of Offline integration](./MIGRATION.md#removal-of-the-offline-integration)
- [Removal of `makeXHRTransport` transport](./MIGRATION.md#removal-of-makexhrtransport-transport)
- [Removal of `wrap` method](./MIGRATION.md#removal-of-wrap-method)

#### Removal of the `BrowserTracing` integration

Expand All @@ -592,6 +593,10 @@ The `Offline` integration has been removed in favor of the
The `makeXHRTransport` transport has been removed. Only `makeFetchTransport` is available now. This means that the
Sentry SDK requires the fetch API to be available in the environment.

#### Removal of `wrap` method

The `wrap` method has been removed. There is no replacement API.

### Server-side SDKs (Node, Deno, Bun, etc.)

Removed top-level exports: `enableAnrDetection`, `Anr`, `deepReadDirSync`
Expand Down
2 changes: 0 additions & 2 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ export {
onLoad,
showReportDialog,
captureUserFeedback,
// eslint-disable-next-line deprecation/deprecation
wrap,
} from './sdk';

export { breadcrumbsIntegration } from './integrations/breadcrumbs';
Expand Down
19 changes: 1 addition & 18 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { dedupeIntegration } from '@sentry/core';
import type { BrowserClientOptions, BrowserOptions } from './client';
import { BrowserClient } from './client';
import { DEBUG_BUILD } from './debug-build';
import { WINDOW, wrap as internalWrap } from './helpers';
import { WINDOW } from './helpers';
import { breadcrumbsIntegration } from './integrations/breadcrumbs';
import { browserApiErrorsIntegration } from './integrations/browserapierrors';
import { globalHandlersIntegration } from './integrations/globalhandlers';
Expand Down Expand Up @@ -268,23 +268,6 @@ export function onLoad(callback: () => void): void {
callback();
}

/**
* 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)();
}

/**
* Enable automatic Session Tracking for the initial page load.
*/
Expand Down
64 changes: 0 additions & 64 deletions packages/browser/test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
getReportDialogEndpoint,
inboundFiltersIntegration,
} from '@sentry/core';
import type { WrappedFunction } from '@sentry/types';
import * as utils from '@sentry/utils';

import type { Event } from '../../src';
Expand All @@ -23,7 +22,6 @@ import {
getCurrentScope,
init,
showReportDialog,
wrap,
} from '../../src';
import { getDefaultBrowserClientOptions } from './helper/browser-client-options';
import { makeSimpleTransport } from './mocks/simpletransport';
Expand Down Expand Up @@ -402,65 +400,3 @@ describe('SentryBrowser initialization', () => {
});
});
});

describe('wrap()', () => {
it('should wrap and call function while capturing error', done => {
const options = getDefaultBrowserClientOptions({
beforeSend: (event: Event): Event | null => {
expect(event.exception!.values![0].type).toBe('TypeError');
expect(event.exception!.values![0].value).toBe('mkey');
done();
return null;
},
dsn,
});
setCurrentClient(new BrowserClient(options));

try {
// eslint-disable-next-line deprecation/deprecation
wrap(() => {
throw new TypeError('mkey');
});
} catch (e) {
// no-empty
}
});

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];
}.bind({ context: 'this' }, 'b', 42),
);

expect((result as unknown[])[0]).toEqual({ context: 'this' });
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;
}.bind({ x: 42 }),
);

expect(result2).toBe(42);
});

it('should ignore frozen functions', () => {
const func = Object.freeze(() => 42);

// eslint-disable-next-line deprecation/deprecation
wrap(func);

expect(func()).toBe(42);
expect((func as WrappedFunction).__sentry_wrapped__).toBeUndefined();
});
});

0 comments on commit 799dab0

Please sign in to comment.