: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(insights): keep raw query errors out of the error heading (#81388)
posthog[bot]4f3c04a91eff
diff --git a/frontend/src/queries/nodes/DataTable/DataTable.tsx b/frontend/src/queries/nodes/DataTable/DataTable.tsxindex 4a021dadda9b..bcb6cc4a3631 100644--- a/frontend/src/queries/nodes/DataTable/DataTable.tsx+++ b/frontend/src/queries/nodes/DataTable/DataTable.tsx@@ -181,6 +181,8 @@ export function DataTable({response,responseLoading,responseError,+ responseErrorObject,+ queryId,queryCancelled,nextDataLoading,newDataLoading,@@ -1042,7 +1044,10 @@ export function DataTable({sourceFeatures.has(QueryFeature.displayResponseError) ? (<InsightErrorStatequery={query}- excludeDetail+ queryId={responseErrorObject?.queryId ?? queryId}+ titleStatus={responseErrorObject?.status}+ // A cancel is the user's own action: no apology or bug-report guidance+ excludeDetail={queryCancelled}onRetry={() => loadData('force_blocking')}title={queryCancelleddiff --git a/frontend/src/queries/nodes/InsightViz/utils.ts b/frontend/src/queries/nodes/InsightViz/utils.tsindex 8d9205354ec8..cd10e9e8256a 100644--- a/frontend/src/queries/nodes/InsightViz/utils.ts+++ b/frontend/src/queries/nodes/InsightViz/utils.ts@@ -195,7 +195,7 @@ export const getQueryBasedDashboard = (// Statuses whose responses carry an actionable validation message: 400 (bad query), 512 (query// estimated too expensive to run), 513 (out of memory)-const VALIDATION_ERROR_STATUSES = new Set([400, 512, 513])+export const VALIDATION_ERROR_STATUSES = new Set([400, 512, 513])const hasValidationErrorStatus = (error: Error | Record<string, any> | null | undefined): boolean =>VALIDATION_ERROR_STATUSES.has((error as Record<string, any> | null | undefined)?.status)diff --git a/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx b/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsxindex 2e32b5e986ce..534c50bd443c 100644--- a/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx+++ b/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx@@ -11,6 +11,7 @@ import { LemonButton } from '@posthog/lemon-ui'import { pngHoggie } from 'lib/brand/hoggies'import { AccessControlAction } from 'lib/components/AccessControlAction'+import { CodeSnippet } from 'lib/components/CodeSnippet'import { MCPUseCaseCard } from 'lib/components/MCPHint/MCPUseCaseCard'import { supportLogic } from 'lib/components/Support/supportLogic'import { dayjs } from 'lib/dayjs'@@ -18,6 +19,7 @@ import { holidaysMatcher, isChristmas } from 'lib/holidays'import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'import { usePageVisibility } from 'lib/hooks/usePageVisibility'import { IconChristmasOrnament, IconErrorOutline, IconOpenInNew } from 'lib/lemon-ui/icons'+import { LemonCollapse } from 'lib/lemon-ui/LemonCollapse'import { LemonMenuOverlay } from 'lib/lemon-ui/LemonMenu/LemonMenu'import { Link } from 'lib/lemon-ui/Link'import { LoadingBar } from 'lib/lemon-ui/LoadingBar'@@ -38,6 +40,7 @@ import { urls } from 'scenes/urls'import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'import { actionsAndEventsToSeries } from '~/queries/nodes/InsightQuery/utils/filtersToQueryNode'import { seriesToActionsAndEvents } from '~/queries/nodes/InsightQuery/utils/queryNodeToFilter'+import { VALIDATION_ERROR_STATUSES } from '~/queries/nodes/InsightViz/utils'import { FunnelsQuery, Node, NodeKind, QueryStatus } from '~/queries/schema/schema-general'import { isFunnelsDataWarehouseNode } from '~/queries/utils'import {@@ -684,8 +687,28 @@ export function InsightValidationError({)}+const RAW_SERVER_ERROR_PATTERN =+ /Stack trace:|DB::Exception|Traceback \(most recent call last\)|object at 0x[0-9a-f]+|^[A-Za-z_.]+(Error|Exception)[:(]/++/**+ * A string title on this state can come straight from the backend, so it can be a raw exception+ * body instead of user-facing copy. Show those behind a collapsible, not in the heading, so the+ * page keeps a clear message with the retry and bug-report guidance. When the response status is+ * known, trust the backend's classification: VALIDATION_ERROR_STATUSES mark messages written for+ * the user (however long), anything else is a server-side failure. Exception markers demote even+ * on those statuses, because staff accounts receive raw traces there too.+ */+export function isRawServerErrorTitle(title: string, status?: number | null): boolean {+ if (RAW_SERVER_ERROR_PATTERN.test(title)) {+ return true+ }+ return status != null && !VALIDATION_ERROR_STATUSES.has(status)+}+export interface InsightErrorStateProps {title?: string | JSX.Element | null+ /** HTTP status of the failed response a string `title` came from, used to tell raw errors from user-facing copy */+ titleStatus?: number | nullquery?: Record<string, any> | Node | nullqueryId?: string | nullexcludeDetail?: boolean@@ -697,6 +720,7 @@ export interface InsightErrorStateProps {export function InsightErrorState({title,+ titleStatus,query,queryId,excludeDetail = false,@@ -705,6 +729,7 @@ export function InsightErrorState({fixWithAIComponent,onRetry,}: InsightErrorStateProps): JSX.Element {+ const rawServerError = typeof title === 'string' && isRawServerErrorTitle(title, titleStatus) ? title : nullconst { preflight } = useValues(preflightLogic)const { openSupportForm } = useActions(supportLogic)@@ -747,9 +772,29 @@ export function InsightErrorState({<h2 className="text-xl text-danger leading-tight mb-6" data-attr="insight-loading-too-long">{/* Note that this default phrasing signals the issue is intermittent, */}{/* and that perhaps the query will complete on retry */}- {title || <span>There was a problem completing this query</span>}+ {!rawServerError && title ? title : <span>There was a problem completing this query</span>}</h2>+ {rawServerError && (+ <LemonCollapse+ className="max-w-160 w-full"+ size="small"+ panels={[+ {+ key: 'error-details',+ header: 'Error details',+ content: (+ // Capped height: in fixed-height hosts (dashboard tiles), an uncapped+ // trace would push the collapse toggle out of the scrollable area+ <CodeSnippet wrap thing="error details" className="max-h-80 overflow-y-auto">+ {rawServerError}+ </CodeSnippet>+ ),+ },+ ]}+ />+ )}+{!excludeDetail && !supportOnly && (<div className="mt-4">We apologize for this unexpected situation. There are a couple of things you can do:diff --git a/frontend/src/scenes/insights/EmptyStates/InsightErrorStates.test.tsx b/frontend/src/scenes/insights/EmptyStates/InsightErrorStates.test.tsxindex 1ba9d889c419..10c5596f16da 100644--- a/frontend/src/scenes/insights/EmptyStates/InsightErrorStates.test.tsx+++ b/frontend/src/scenes/insights/EmptyStates/InsightErrorStates.test.tsx@@ -1,4 +1,4 @@-import { cleanup, render, screen } from '@testing-library/react'+import { cleanup, fireEvent, render, screen } from '@testing-library/react'import posthog from 'posthog-js'import { preflightLogic } from 'lib/logic/preflightLogic'@@ -6,7 +6,7 @@ import { preflightLogic } from 'lib/logic/preflightLogic'import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'-import { InsightErrorState, InsightValidationError } from './EmptyStates'+import { InsightErrorState, InsightValidationError, isRawServerErrorTitle } from './EmptyStates'describe('insight error states', () => {let captureSpy: jest.SpyInstance@@ -69,6 +69,45 @@ describe('insight error states', () => {expect(container.querySelector('.LemonButtonWithSideAction') !== null).toBe(expectsSideAction)})+ // Long enough that a length heuristic would misclassify it as a raw server error+ const longCuratedMessage =+ 'The estimated query size exceeds the limit for this project. Narrow the date range, remove ' ++ 'high-cardinality breakdowns, or materialize the source view, then run the query again. See ' ++ 'the query performance docs for the limits that apply.'++ it.each([+ { title: 'Code: 47. DB::Exception: Not found column mat_$survey_submission_id', status: undefined, raw: true },+ { title: 'Some error\nStack trace:\n0. DB::Exception::Exception()', status: undefined, raw: true },+ { title: 'Traceback (most recent call last): File "x.py"', status: undefined, raw: true },+ { title: '<QuerySomething object at 0x7f1234>', status: undefined, raw: true },+ { title: 'ValueError: bad input', status: undefined, raw: true },+ // Validation statuses carry user-facing copy, no matter how long+ { title: longCuratedMessage, status: 400, raw: false },+ { title: longCuratedMessage, status: undefined, raw: false },+ // ...but staff accounts receive raw traces on validation statuses too+ { title: 'Code: 241. DB::Exception: Memory limit exceeded. Stack trace:\n0.', status: 400, raw: true },+ // Non-validation statuses mean a server-side failure whose text is not meant for the heading+ { title: 'ClickHouse error while executing query.', status: 500, raw: true },+ { title: 'The query was cancelled', status: undefined, raw: false },+ { title: 'This project has no events yet', status: undefined, raw: false },+ ])('classifies "$title" (status: $status) as raw=$raw', ({ title, status, raw }) => {+ expect(isRawServerErrorTitle(title, status)).toBe(raw)+ })++ it('keeps a raw ClickHouse error out of the heading but reachable in the details panel', () => {+ const clickhouseError =+ 'Code: 47. DB::Exception: Not found column mat_$survey_submission_id. Stack trace:\n0. DB::Exception::Exception()'+ const { container } = render(<InsightErrorState title={clickhouseError} onRetry={() => {}} />)++ const heading = container.querySelector('[data-attr="insight-loading-too-long"]')+ expect(heading?.textContent).toBe('There was a problem completing this query')+ // The raw error stays hidden until the user opens the details panel.+ expect(screen.queryByText(/DB::Exception/)).toBeNull()++ fireEvent.click(screen.getByText('Error details'))+ expect(screen.getByText(/DB::Exception/)).toBeTruthy()+ })+it('shows support without retry guidance for persistent errors', () => {preflightLogic.actions.loadPreflightSuccess({ cloud: true } as any)