Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(browser): Deprecate top-level wrap function #8927

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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