From a4cad7735d1e7a64d6048b3f395bef68b6d96e45 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Thu, 3 Dec 2020 13:54:02 +0100 Subject: [PATCH] Catch @hapi/podium errors (#84575) (#84867) --- .../src/legacy_logging_server.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/kbn-legacy-logging/src/legacy_logging_server.ts b/packages/kbn-legacy-logging/src/legacy_logging_server.ts index 1b13eda44fff2..1533bde4fc17b 100644 --- a/packages/kbn-legacy-logging/src/legacy_logging_server.ts +++ b/packages/kbn-legacy-logging/src/legacy_logging_server.ts @@ -117,11 +117,18 @@ export class LegacyLoggingServer { public log({ level, context, message, error, timestamp, meta = {} }: LogRecord) { const { tags = [], ...metadata } = meta; - this.events.emit('log', { - data: getDataToLog(error, metadata, message), - tags: [getLegacyLogLevel(level), ...context.split('.'), ...tags], - timestamp: timestamp.getTime(), - }); + this.events + .emit('log', { + data: getDataToLog(error, metadata, message), + tags: [getLegacyLogLevel(level), ...context.split('.'), ...tags], + timestamp: timestamp.getTime(), + }) + // @ts-expect-error @hapi/podium emit is actually an async function + .catch((err) => { + // eslint-disable-next-line no-console + console.error('An unexpected error occurred while writing to the log:', err.stack); + process.exit(1); + }); } public stop() {