mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Log Unhandled rejection stack (#113614)
* Refactor state types
* Log the stack trace of unhandled promise rejections
* Revert "Refactor state types"
This reverts commit 6a5123a1b2
.
* Fix types
* code review feedback
This commit is contained in:
parent
a03aa7b7fa
commit
f88901c6ac
2 changed files with 29 additions and 2 deletions
|
@ -135,6 +135,32 @@ describe('UuidService', () => {
|
|||
expect(logger.get('process').warn).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('unhandledRejection warnings', () => {
|
||||
it('logs warn for an unhandeld promise rejected with an Error', async () => {
|
||||
await service.preboot();
|
||||
|
||||
const err = new Error('something went wrong');
|
||||
process.emit('unhandledRejection', err, new Promise((res, rej) => rej(err)));
|
||||
|
||||
expect(logger.get('process').warn).toHaveBeenCalledTimes(1);
|
||||
expect(loggingSystemMock.collect(logger).warn[0][0]).toMatch(
|
||||
/Detected an unhandled Promise rejection: Error: something went wrong\n.*at /
|
||||
);
|
||||
});
|
||||
|
||||
it('logs warn for an unhandeld promise rejected with a string', async () => {
|
||||
await service.preboot();
|
||||
|
||||
const err = 'something went wrong';
|
||||
process.emit('unhandledRejection', err, new Promise((res, rej) => rej(err)));
|
||||
|
||||
expect(logger.get('process').warn).toHaveBeenCalledTimes(1);
|
||||
expect(loggingSystemMock.collect(logger).warn[0][0]).toMatch(
|
||||
/Detected an unhandled Promise rejection: "something went wrong"/
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setup()', () => {
|
||||
|
|
|
@ -54,9 +54,10 @@ export class EnvironmentService {
|
|||
this.configService.atPath<PidConfigType>(pidConfigDef.path).pipe(take(1)).toPromise(),
|
||||
]);
|
||||
|
||||
// was present in the legacy `pid` file.
|
||||
// Log unhandled rejections so that we can fix them in preparation for https://github.com/elastic/kibana/issues/77469
|
||||
process.on('unhandledRejection', (reason) => {
|
||||
this.log.warn(`Detected an unhandled Promise rejection.\n${reason}`);
|
||||
const message = (reason as Error)?.stack ?? JSON.stringify(reason);
|
||||
this.log.warn(`Detected an unhandled Promise rejection: ${message}`);
|
||||
});
|
||||
|
||||
process.on('warning', (warning) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue