[KibanaErrorBoundary] Log the error that was caught (#189925)

Log the error that was caught to the console, so developers can interact
with the stack trace messages.

Addresses
https://github.com/elastic/kibana/pull/168754#issuecomment-2268523404
This commit is contained in:
Tim Sullivan 2024-08-06 11:49:44 -07:00 committed by GitHub
parent 83f6fa4872
commit 6b4f613ac2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 0 deletions

View file

@ -17,6 +17,7 @@ import { BadComponent } from '../../mocks';
describe('<KibanaErrorBoundaryProvider>', () => {
let analytics: KibanaErrorBoundaryProviderDeps['analytics'];
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(() => {});
analytics = analyticsServiceMock.createAnalyticsServiceStart();
});

View file

@ -9,6 +9,10 @@
import { KibanaErrorService } from './error_service';
describe('KibanaErrorBoundary Error Service', () => {
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(() => {});
});
const mockDeps = {
analytics: { reportEvent: jest.fn() },
};

View file

@ -19,6 +19,7 @@ import { errorMessageStrings as strings } from './message_strings';
describe('<KibanaErrorBoundary>', () => {
let services: KibanaErrorBoundaryServices;
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(() => {});
services = getServicesMock();
});

View file

@ -42,6 +42,9 @@ class ErrorBoundaryInternal extends React.Component<
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error('Error caught by Kibana React Error Boundary'); // 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(() => {
return { error, errorInfo, componentName: name, isFatal };