From 7f6be4815b557f5bb5015565c330642746e7a194 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Wed, 4 Oct 2023 17:15:16 +0100 Subject: [PATCH] fix: event is sometimes null (#17784) --- plugin-server/src/worker/ingestion/process-event.ts | 4 +++- plugin-server/tests/main/process-event.test.ts | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin-server/src/worker/ingestion/process-event.ts b/plugin-server/src/worker/ingestion/process-event.ts index afb55e648dbcb..73e8249626a7b 100644 --- a/plugin-server/src/worker/ingestion/process-event.ts +++ b/plugin-server/src/worker/ingestion/process-event.ts @@ -359,7 +359,9 @@ export const gatherConsoleLogEvents = ( const consoleLogEntries: ConsoleLogEntry[] = [] events.forEach((event) => { - if (event.type === RRWebEventType.Plugin && event.data?.plugin === 'rrweb/console@1') { + // it should be unnecessary to check for truthiness of event here, + // but we've seen null in production so 🤷 + if (!!event && event.type === RRWebEventType.Plugin && event.data?.plugin === 'rrweb/console@1') { const level = event.data.payload?.level const message = safeString(event.data.payload?.payload) consoleLogEntries.push({ diff --git a/plugin-server/tests/main/process-event.test.ts b/plugin-server/tests/main/process-event.test.ts index 0d1fd352f17b5..94587c6770773 100644 --- a/plugin-server/tests/main/process-event.test.ts +++ b/plugin-server/tests/main/process-event.test.ts @@ -1497,6 +1497,7 @@ test('simple console log processing', () => { }, }, }, + null as unknown as RRWebEvent, // see https://posthog.sentry.io/issues/4525043303 ]) expect(consoleLogEntries).toEqual([ {