:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(error-tracking): stop a malformed exception payload crashing the panel (#96366)
Christiaan Hendriksen73421774fd47
diff --git a/frontend/src/lib/components/Errors/utils.test.ts b/frontend/src/lib/components/Errors/utils.test.tsindex 5b52cab56932..b5dc5c3ec55c 100644--- a/frontend/src/lib/components/Errors/utils.test.ts+++ b/frontend/src/lib/components/Errors/utils.test.ts@@ -275,4 +275,44 @@ describe('Error Display', () => {])('reads the instruction address from %s', (_name, junk_drawer, expected) => {expect(getInstructionAddress({ junk_drawer } as ErrorTrackingStackFrame)).toEqual(expected)})++ it.each<[string, unknown[], unknown[]]>([+ ['every frame replaced by a truncation marker', ['[TRUNCATED]', '[TRUNCATED]'], []],+ ['a raw stack trace line', ['at handleRequest (file:///srv/app/server.js:42:9)'], []],+ ['a null frame', [null], []],+ ['a valid frame next to a string', [{ raw_id: 'abc' }, '[TRUNCATED]'], [{ raw_id: 'abc/0' }]],+ ['a non-string raw id', [{ raw_id: 1234 }], [{ raw_id: 1234 }]],+ ])('survives malformed stack frames, given %s', (_name, frames, expected) => {+ const properties = {+ $exception_list: [{ type: 'Error', value: 'boom', stacktrace: { frames } }],+ } as unknown as ErrorEventProperties++ expect(getExceptionList(properties)[0]?.stacktrace?.frames).toEqual(expected)+ })++ it.each<[string, unknown[], unknown[]]>([+ ['a null exception', [null], []],+ ['an exception replaced by a truncation marker', ['[TRUNCATED]'], []],+ [+ 'a valid exception next to a null',+ [{ type: 'Error', value: 'boom' }, null],+ [{ type: 'Error', value: 'boom' }],+ ],+ ])('drops exception entries that are not objects, given %s', (_name, $exception_list, expected) => {+ const properties = { $exception_list } as unknown as ErrorEventProperties++ expect(getExceptionList(properties)).toEqual(expected)+ })++ it('leaves the event properties it reads unchanged', () => {+ const frame = { raw_id: 'abc' }+ const properties = {+ $exception_list: [{ type: 'Error', value: 'boom', stacktrace: { frames: [frame] } }],+ } as unknown as ErrorEventProperties++ const result = getExceptionList(properties)++ expect(result[0].stacktrace?.frames[0].raw_id).toEqual('abc/0')+ expect(frame.raw_id).toEqual('abc')+ })})diff --git a/frontend/src/lib/components/Errors/utils.ts b/frontend/src/lib/components/Errors/utils.tsindex 9218356354c6..1abc9a897cfb 100644--- a/frontend/src/lib/components/Errors/utils.ts+++ b/frontend/src/lib/components/Errors/utils.ts@@ -1,5 +1,7 @@import { P, match } from 'ts-pattern'+import { isObject } from 'lib/utils/guards'+import { isPostHogProperty } from '~/taxonomy/taxonomy'import {@@ -176,17 +178,25 @@ function processExceptionList(exceptionList: ErrorTrackingException[] = []): Err}function ensureFrameIdFormat(exceptionList: ErrorTrackingException[]): ErrorTrackingException[] {- exceptionList = exceptionList.map((exception) => {- if (!exception.stacktrace || !exception.stacktrace.frames || !Array.isArray(exception.stacktrace.frames)) {+ return exceptionList.map((exception) => {+ const stacktrace = exception.stacktrace+ if (!stacktrace || !Array.isArray(stacktrace.frames)) {return exception}- exception.stacktrace.frames = exception.stacktrace.frames.map((frame) => {- frame.raw_id = frame.raw_id ? coerceLegacyRawId(frame.raw_id) : frame.raw_id- return frame- })- return exception+ const frames = stacktrace.frames.filter(isFrameObject).map((frame) => ({+ ...frame,+ raw_id: typeof frame.raw_id === 'string' && frame.raw_id ? coerceLegacyRawId(frame.raw_id) : frame.raw_id,+ }))+ return { ...exception, stacktrace: { ...stacktrace, frames } }})- return exceptionList+}++function isFrameObject(frame: unknown): frame is ErrorTrackingStackFrame {+ return isObject(frame)+}++function isExceptionObject(exception: unknown): exception is ErrorTrackingException {+ return isObject(exception)}function coerceLegacyRawId(rawId: string): string {@@ -259,7 +269,7 @@ function ensureStringExceptionValues(exceptionList: ErrorTrackingException[]): Ereturn []}- return exceptionList.map((exception) => ({+ return exceptionList.filter(isExceptionObject).map((exception) => ({...exception,value: stringify(exception.value),}))