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

fix: remove top level errors from pagerror events #862

Merged
merged 1 commit into from
Nov 1, 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
4 changes: 0 additions & 4 deletions __tests__/plugins/browser-console.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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');
});

Expand Down
2 changes: 1 addition & 1 deletion __tests__/reporters/__snapshots__/json.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
"
`;
1 change: 0 additions & 1 deletion __tests__/reporters/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ describe('json reporter', () => {
text: 'Boom',
type: 'error',
step: { name: 'step-name', index: 0 },
error,
},
],
});
Expand Down
1 change: 0 additions & 1 deletion src/common_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ export type PageMetrics = Record<string, number>;
export type BrowserMessage = {
text: string;
type: string;
error?: Error;
} & DefaultPluginOutput;

export type PluginOutput = {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/browser-console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class BrowserConsole {
text: error.message,
type: 'error',
step: { name, index },
error,
});

this.enforceMessagesLimit();
Expand Down
18 changes: 3 additions & 15 deletions src/reporters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
*/
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
});
Expand Down