From 6d0508636262a38bb79d3dbe5bcde091e7fd5c32 Mon Sep 17 00:00:00 2001 From: vigneshshanmugam Date: Wed, 1 Nov 2023 10:55:47 -0700 Subject: [PATCH] fix: remove top level errors from pagerror events --- __tests__/plugins/browser-console.test.ts | 4 ---- .../reporters/__snapshots__/json.test.ts.snap | 2 +- __tests__/reporters/json.test.ts | 1 - src/common_types.ts | 1 - src/plugins/browser-console.ts | 1 - src/reporters/json.ts | 18 +++--------------- 6 files changed, 4 insertions(+), 23 deletions(-) diff --git a/__tests__/plugins/browser-console.test.ts b/__tests__/plugins/browser-console.test.ts index a61002d2..627b5f63 100644 --- a/__tests__/plugins/browser-console.test.ts +++ b/__tests__/plugins/browser-console.test.ts @@ -98,9 +98,6 @@ describe('BrowserConsole', () => { const referenceError = messages.find( m => m.text.indexOf('that is not defined') >= 0 ); - expect(referenceError?.error?.stack).toContain( - `ReferenceError: that is not defined\n at HTMLImageElement.onerror` - ); expect(referenceError?.type).toEqual('error'); expect(referenceError?.step).toEqual(currentStep); }); @@ -134,7 +131,6 @@ describe('BrowserConsole', () => { const [page1Err, page2Err] = messages; expect(page1Err?.type).toEqual('error'); expect(page1Err?.step).toEqual(currentStep); - expect(page1Err?.error?.stack).toContain('Error: Boom'); expect(page2Err?.text).toEqual('popup error'); }); diff --git a/__tests__/reporters/__snapshots__/json.test.ts.snap b/__tests__/reporters/__snapshots__/json.test.ts.snap index 5f226ba3..00c53384 100644 --- a/__tests__/reporters/__snapshots__/json.test.ts.snap +++ b/__tests__/reporters/__snapshots__/json.test.ts.snap @@ -209,7 +209,7 @@ exports[`json reporter writes each step as NDJSON to the FD 1`] = ` {"type":"step/filmstrips","@timestamp":1600300800000000,"journey":{"name":"j1","id":"j1"},"step":{"name":"s1","index":1},"root_fields":{"browser":{"relative_trace":{"start":{"us":392583998697}}},"os":{"platform":"darwin"},"package":{"name":"@elastic/synthetics","version":"0.0.1"}},"payload":{"index":0},"blob":"dummy","blob_mime":"image/jpeg","package_version":"0.0.1"} {"type":"step/end","@timestamp":1600300800000000,"journey":{"name":"j1","id":"j1"},"step":{"name":"s1","index":1,"status":"succeeded","duration":{"us":10000000}},"root_fields":{"os":{"platform":"darwin"},"package":{"name":"@elastic/synthetics","version":"0.0.1"}},"payload":{"source":"function noop() { }","url":"dummy","status":"succeeded"},"url":"dummy","package_version":"0.0.1"} {"type":"journey/network_info","@timestamp":1600300800000000,"journey":{"name":"j1","id":"j1"},"root_fields":{"user_agent":{},"http":{"request":{}},"os":{"platform":"darwin"},"package":{"name":"@elastic/synthetics","version":"0.0.1"}},"payload":{"browser":{},"is_navigation_request":true},"package_version":"0.0.1"} -{"type":"journey/browserconsole","@timestamp":1600300800000000,"journey":{"name":"j1","id":"j1"},"step":{"name":"step-name","index":0},"root_fields":{"os":{"platform":"darwin"},"package":{"name":"@elastic/synthetics","version":"0.0.1"}},"payload":{"text":"Boom","type":"error"},"error":{"name":"Error","message":"boom","stack":"at /foo/bar.js:1:1"},"package_version":"0.0.1"} +{"type":"journey/browserconsole","@timestamp":1600300800000000,"journey":{"name":"j1","id":"j1"},"step":{"name":"step-name","index":0},"root_fields":{"os":{"platform":"darwin"},"package":{"name":"@elastic/synthetics","version":"0.0.1"}},"payload":{"text":"Boom","type":"error"},"package_version":"0.0.1"} {"type":"journey/end","@timestamp":1600300800000000,"journey":{"name":"j1","id":"j1","status":"succeeded"},"root_fields":{"os":{"platform":"darwin"},"package":{"name":"@elastic/synthetics","version":"0.0.1"}},"payload":{"start":0,"end":11,"status":"succeeded"},"package_version":"0.0.1"} " `; diff --git a/__tests__/reporters/json.test.ts b/__tests__/reporters/json.test.ts index fb620801..ec918fd4 100644 --- a/__tests__/reporters/json.test.ts +++ b/__tests__/reporters/json.test.ts @@ -174,7 +174,6 @@ describe('json reporter', () => { text: 'Boom', type: 'error', step: { name: 'step-name', index: 0 }, - error, }, ], }); diff --git a/src/common_types.ts b/src/common_types.ts index 3b2a0f26..8fd96f9d 100644 --- a/src/common_types.ts +++ b/src/common_types.ts @@ -182,7 +182,6 @@ export type PageMetrics = Record; export type BrowserMessage = { text: string; type: string; - error?: Error; } & DefaultPluginOutput; export type PluginOutput = { diff --git a/src/plugins/browser-console.ts b/src/plugins/browser-console.ts index 9e48960d..1b8f6f3d 100644 --- a/src/plugins/browser-console.ts +++ b/src/plugins/browser-console.ts @@ -69,7 +69,6 @@ export class BrowserConsole { text: error.message, type: 'error', step: { name, index }, - error, }); this.enforceMessagesLimit(); diff --git a/src/reporters/json.ts b/src/reporters/json.ts index 6d2530be..5a3d907b 100644 --- a/src/reporters/json.ts +++ b/src/reporters/json.ts @@ -194,7 +194,7 @@ export function formatNetworkFields(network: NetworkInfo) { * formatJSONError formats the error in a structured format * we restructure the error with code frame and stack trace for test errors */ -function formatJSONError(error: Error | any, type: OutputType) { +function formatJSONError(error: Error | any) { if (error == null) { return; } @@ -204,17 +204,6 @@ function formatJSONError(error: Error | any, type: OutputType) { return { message: `thrown: ${inspect(error)}` }; } - /** - * Do not process browser errors - console.error and unhandled exceptions - */ - if (type != null && type === 'journey/browserconsole') { - return { - name: error.name, - message: error.message, - stack: error.stack, - }; - } - /** * Do not highlight source for these errors and strip ANSI codes */ @@ -479,13 +468,12 @@ export default class JSONReporter extends BaseReporter { } if (browserconsole) { - browserconsole.forEach(({ timestamp, text, type, step, error }) => { + browserconsole.forEach(({ timestamp, text, type, step }) => { this.writeJSON({ type: 'journey/browserconsole', journey, timestamp, step, - error, payload: { text, type, @@ -586,7 +574,7 @@ export default class JSONReporter extends BaseReporter { payload, blob, blob_mime, - error: formatJSONError(error, type), + error: formatJSONError(error), url, package_version: version, });