Skip to content

Commit c1e7138

Browse files
committed
fix Error instantiation for debugId injection snippet
1 parent d857f8c commit c1e7138

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

packages/bundler-plugin-core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ export function createComponentNameAnnotateHooks() {
666666
}
667667

668668
export function getDebugIdSnippet(debugId: string): string {
669-
return `;!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="${debugId}",e._sentryDebugIdIdentifier="sentry-dbid-${debugId}")}catch(e){}}();`;
669+
return `;!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="${debugId}",e._sentryDebugIdIdentifier="sentry-dbid-${debugId}")}catch(e){}}();`;
670670
}
671671

672672
export { stringToUUID, replaceBooleanFlagsInCode } from "./utils";
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { getDebugIdSnippet } from "../src";
2+
3+
describe("getDebugIdSnippet", () => {
4+
it("returns the debugId injection snippet for a passed debugId", () => {
5+
const snippet = getDebugIdSnippet("1234");
6+
expect(snippet).toMatchInlineSnapshot(
7+
`";!function(){try{var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\\"1234\\",e._sentryDebugIdIdentifier=\\"sentry-dbid-1234\\")}catch(e){}}();"`
8+
);
9+
});
10+
});

packages/integration-tests/fixtures/debug-id-injection/debug-id-injection.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function checkBundle(bundlePath1: string, bundlePath2: string): string[] {
1313
expect.stringMatching(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/)
1414
);
1515

16+
expect(Object.keys(debugIdMap1)[0]).toContain("Error");
17+
1618
const process2Output = childProcess.execSync(`node ${bundlePath2}`, { encoding: "utf-8" });
1719
const debugIdMap2 = JSON.parse(process2Output) as Record<string, string>;
1820
const debugIds2 = Object.values(debugIdMap2);
@@ -21,6 +23,8 @@ function checkBundle(bundlePath1: string, bundlePath2: string): string[] {
2123
expect.stringMatching(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/)
2224
);
2325

26+
expect(Object.keys(debugIdMap2)[0]).toContain("Error");
27+
2428
expect(debugIds1).not.toEqual(debugIds2);
2529

2630
return [...debugIds1, ...debugIds2];

0 commit comments

Comments
 (0)