Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export const getErrorBoundaryLabels = (
errorType: 'PageFatalReactError' | 'SectionFatalReactError'
) => {
return {
errorType,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { mutateError } from './mutate_error';
export { getErrorBoundaryLabels } from './error_boundary_labels';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('<KibanaErrorBoundaryProvider>', () => {
expect(reportEventSpy).toBeCalledWith('fatal-error-react', {
component_name: 'BadComponent',
component_stack: expect.any(String),
error_message: 'FatalReactError: This is an error to show the test user!',
error_message: 'Error: This is an error to show the test user!',
error_stack: expect.any(String),
});
});
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('<KibanaErrorBoundaryProvider>', () => {
expect(reportEventSpy1).toBeCalledWith('fatal-error-react', {
component_name: 'BadComponent',
component_stack: expect.any(String),
error_message: 'FatalReactError: This is an error to show the test user!',
error_message: 'Error: This is an error to show the test user!',
error_stack: expect.any(String),
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export class KibanaErrorService {
* or treated with "danger" coloring and include a detailed error message.
*/
private getIsFatal(error: Error) {
const customError: Error & { react_error_type?: string; original_name?: string } = error;
const errorName = customError.original_name ?? customError.name;
const isChunkLoadError = MATCH_CHUNK_LOADERROR.test(errorName);
const isChunkLoadError = MATCH_CHUNK_LOADERROR.test(error.name);
return !isChunkLoadError; // "ChunkLoadError" is recoverable by refreshing the page
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('<KibanaErrorBoundary>', () => {
expect(mockDeps.analytics.reportEvent.mock.calls[0][0]).toBe('fatal-error-react');
expect(mockDeps.analytics.reportEvent.mock.calls[0][1]).toMatchObject({
component_name: 'BadComponent',
error_message: 'FatalReactError: This is an error to show the test user!',
error_message: 'Error: This is an error to show the test user!',
});
});

Expand All @@ -118,7 +118,7 @@ describe('<KibanaErrorBoundary>', () => {
).toBe(true);
expect(
mockDeps.analytics.reportEvent.mock.calls[0][1].error_stack.startsWith(
'FatalReactError: This is an error to show the test user!'
'Error: This is an error to show the test user!'
)
).toBe(true);
});
Expand All @@ -133,15 +133,8 @@ describe('<KibanaErrorBoundary>', () => {

expect(apm.captureError).toHaveBeenCalledTimes(1);
expect(apm.captureError).toHaveBeenCalledWith(
new Error('This is an error to show the test user!')
);
expect(Object.keys((apm.captureError as jest.Mock).mock.calls[0][0])).toEqual([
'react_error_type',
'original_name',
'name',
]);
expect((apm.captureError as jest.Mock).mock.calls[0][0].react_error_type).toEqual(
'fatal-error-react'
new Error('This is an error to show the test user!'),
{ labels: { errorType: 'PageFatalReactError' } }
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { apm } from '@elastic/apm-rum';
import React from 'react';

import { mutateError } from '../../lib';
import { getErrorBoundaryLabels } from '../../lib';
import type { KibanaErrorBoundaryServices } from '../../types';
import { useErrorBoundary } from '../services';
import { FatalPrompt, RecoverablePrompt } from './message_components';
Expand Down Expand Up @@ -41,10 +41,11 @@ class ErrorBoundaryInternal extends React.Component<
}

componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
const customError = mutateError(error);
apm.captureError(customError);
apm.captureError(error, {
labels: getErrorBoundaryLabels('PageFatalReactError'),
});
console.error('Error caught by Kibana React Error Boundary'); // eslint-disable-line no-console
console.error(customError); // eslint-disable-line no-console
console.error(error); // eslint-disable-line no-console

const { name, isFatal } = this.props.services.errorService.registerError(error, errorInfo);
this.setState(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('<KibanaSectionErrorBoundary>', () => {
expect(mockDeps.analytics.reportEvent.mock.calls[0][0]).toBe('fatal-error-react');
expect(mockDeps.analytics.reportEvent.mock.calls[0][1]).toMatchObject({
component_name: 'BadComponent',
error_message: 'FatalReactError: This is an error to show the test user!',
error_message: 'Error: This is an error to show the test user!',
});
});

Expand All @@ -114,7 +114,7 @@ describe('<KibanaSectionErrorBoundary>', () => {
).toBe(true);
expect(
mockDeps.analytics.reportEvent.mock.calls[0][1].error_stack.startsWith(
'FatalReactError: This is an error to show the test user!'
'Error: This is an error to show the test user!'
)
).toBe(true);
});
Expand All @@ -129,15 +129,8 @@ describe('<KibanaSectionErrorBoundary>', () => {

expect(apm.captureError).toHaveBeenCalledTimes(1);
expect(apm.captureError).toHaveBeenCalledWith(
new Error('This is an error to show the test user!')
);
expect(Object.keys((apm.captureError as jest.Mock).mock.calls[0][0])).toEqual([
'react_error_type',
'original_name',
'name',
]);
expect((apm.captureError as jest.Mock).mock.calls[0][0].react_error_type).toEqual(
'fatal-error-react'
new Error('This is an error to show the test user!'),
{ labels: { errorType: 'SectionFatalReactError' } }
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { apm } from '@elastic/apm-rum';
import React from 'react';
import { apm } from '@elastic/apm-rum';

import { mutateError } from '../../lib';
import { getErrorBoundaryLabels } from '../../lib';
import type { KibanaErrorBoundaryServices } from '../../types';
import { useErrorBoundary } from '../services';
import { SectionFatalPrompt, SectionRecoverablePrompt } from './message_components';
Expand Down Expand Up @@ -65,10 +65,11 @@ class SectionErrorBoundaryInternal extends React.Component<
}

componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {
const customError = mutateError(error);
apm.captureError(customError);
apm.captureError(error, {
labels: getErrorBoundaryLabels('SectionFatalReactError'),
});
console.error('Error caught by Kibana React Error Boundary'); // eslint-disable-line no-console
console.error(customError); // eslint-disable-line no-console
console.error(error); // eslint-disable-line no-console

const { name, isFatal } = this.props.services.errorService.registerError(error, errorInfo);
this.setState({ error, errorInfo, componentName: name, isFatal });
Expand Down