Skip to content

Commit

Permalink
ref(browser): Deprecate top-level wrap function (#8927)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Lms24 committed Sep 4, 2023
1 parent fe375b9 commit eb29981
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
5 changes: 5 additions & 0 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)();
Expand Down
4 changes: 4 additions & 0 deletions packages/browser/test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ describe('wrap()', () => {
getCurrentHub().bindClient(new BrowserClient(options));

try {
// eslint-disable-next-line deprecation/deprecation
wrap(() => {
throw new TypeError('mkey');
});
Expand All @@ -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];
Expand All @@ -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;
Expand Down

0 comments on commit eb29981

Please sign in to comment.