Skip to content

: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.

fix(logs): guard against an empty logs query response before reading its fields (#73880)

posthog[bot]ca889758306e
diff --git a/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.ts b/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.ts
index 97a863c0cc9a..34c9f118b46a 100644
--- a/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.ts
+++ b/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.ts
@@ -692,6 +692,12 @@ export const logsViewerDataLogic = kea<logsViewerDataLogicType>([
signal,
})
actions.setLogsAbortController(null)
+ // A 2xx response with an empty body legitimately resolves to null (see
+ // getJSONFromSuccessResponse in lib/api.ts) — treat it as a failure instead of
+ // crashing on the first property access below.
+ if (!response) {
+ throw new Error('Logs query returned an empty response')
+ }
actions.setHasMoreLogsToLoad(!!response.hasMore)
actions.setNextCursor(response.nextCursor ?? null)
actions.setMaxExportableLogs(response.maxExportableLogs)
@@ -738,6 +744,10 @@ export const logsViewerDataLogic = kea<logsViewerDataLogicType>([
signal,
})
actions.setLogsAbortController(null)
+ // See the matching guard in fetchLogs: an empty-body 2xx response resolves to null.
+ if (!response) {
+ throw new Error('Logs query returned an empty response')
+ }
actions.setHasMoreLogsToLoad(!!response.hasMore)
actions.setNextCursor(response.nextCursor ?? null)
return [...values.logs, ...response.results]