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.

feat(data-warehouse): show the failure reason in materialization runs (#93717)

Thiago Salvatore69cc63ffd55e
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index a5800c3a2f76..2148ff462194 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6600,6 +6600,14 @@ snapshots:
hash: v1.k794b7964.f90080b48e02650b50bee9d714dc226f41aec9108a4878a67abccc18735aa7a2.9vBFfiHItb00dBAS4YWq2EugPAeQUVjYFkobGWL8pHE
scenes-app-data-pipelines-event-filtering--switch-mode-to-dry-run--light:
hash: v1.k794b7964.ac76cb9e4e3fb7b45c5feadceb9e14744becd1935a7a6bbe7f5f775a7d3ef9e2.z3k9FQwdN9CDRW-qb07bLD5FTh2wGHdRVMhKL9Fbzms
+ scenes-app-data-warehouse-materialization-run-error--completed-run-with-warning--dark:
+ hash: v1.k794b7964.f2c6214ec82028727b31878d8fd74af3aaf2db665c30dfa5194bf688984b58a2.JnE5GZdjA26G7aB-Rtcll6JaRXr-QGKr1dOn4E1SqTk
+ scenes-app-data-warehouse-materialization-run-error--completed-run-with-warning--light:
+ hash: v1.k794b7964.c7874415ab58fff8f524ca56fb5392d98e59528fb78e6ea07b6eaf8ff18fe089.cOPyiv0KTYJNyL1p_B1nkuKMr95UGk6WuvM6aFP1O4g
+ scenes-app-data-warehouse-materialization-run-error--failed-run--dark:
+ hash: v1.k794b7964.036944f812c493e6ebf4cde79bf720281a4d89aafbccbca6ef4e95c850ab9993.Ig4AN3DFHkKwmAsquefZLAArrhv2pnvU91KbrPIX7n8
+ scenes-app-data-warehouse-materialization-run-error--failed-run--light:
+ hash: v1.k794b7964.ed511cb8d3c6d75a764e3dbd7dfd283701c36071223f8425c99fc31813f0e51b.F9o4sSmrCS472D2cERRD1byomuvBDEp_5cy26VarG9s
scenes-app-data-warehouse-query-index-usage--every-filter-indexed--dark:
hash: v1.k794b7964.5593a848fb86d8d93d2d347b17de81b878cff3e9d69ccf976562e60bddeb71fa.-EnSwW5B20DYmE0dRl-8VfENfxJMJrMl-vWmmkJ1sG0
scenes-app-data-warehouse-query-index-usage--every-filter-indexed--light:
diff --git a/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx b/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx
index 96e716547292..bb62494bb3ec 100644
--- a/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx
+++ b/frontend/src/scenes/data-warehouse/saved_queries/MaterializationStatusPanel.tsx
@@ -18,6 +18,8 @@ import { userLogic } from 'scenes/userLogic'
import { AccessControlLevel, AccessControlResourceType, DataModelingJob, LogEntryLevel } from '~/types'
+import { MaterializationRunErrorCell } from 'products/data_warehouse/frontend/shared/components/MaterializationRunErrorCell'
+
import { IncrementalConfigOptions } from '../editor/IncrementalConfigFields'
import { dataWarehouseViewsLogic } from './dataWarehouseViewsLogic'
import { materializationJobsLogic } from './materializationJobsLogic'
@@ -522,7 +524,7 @@ export function MaterializationStatusPanel({
title: 'Status',
dataIndex: 'status',
render: (_, job: DataModelingJob) => {
- const { status, error, rows_materialized, rows_expected } = job
+ const { status, rows_materialized, rows_expected } = job
const statusToType: Record<string, LemonTagType> = {
Completed: 'success',
Failed: 'danger',
@@ -553,14 +555,7 @@ export function MaterializationStatusPanel({
)
}
- const statusTag =
- error && status !== 'Completed' ? (
- <Tooltip title={error} interactive>
- <LemonTag type={type}>{status}</LemonTag>
- </Tooltip>
- ) : (
- <LemonTag type={type}>{status}</LemonTag>
- )
+ const statusTag = <LemonTag type={type}>{status}</LemonTag>
return (
<div className="flex items-center gap-1">
{statusTag}
@@ -573,6 +568,13 @@ export function MaterializationStatusPanel({
)
},
},
+ {
+ title: 'Error',
+ dataIndex: 'error',
+ render: (_, { error, status }: DataModelingJob) => (
+ <MaterializationRunErrorCell error={error} status={status} />
+ ),
+ },
{
title: 'Rows',
dataIndex: 'rows_materialized',
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7ed3ed69ef76..89e9082f3b13 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -3124,6 +3124,13 @@ importers:
react:
specifier: 18.3.1
version: 18.3.1
+ devDependencies:
+ '@testing-library/jest-dom':
+ specifier: ^5.17.0
+ version: 5.17.0
+ '@testing-library/react':
+ specifier: ^14.3.1
products/demo: {}
diff --git a/products/data_warehouse/frontend/shared/components/MaterializationRunErrorCell.stories.tsx b/products/data_warehouse/frontend/shared/components/MaterializationRunErrorCell.stories.tsx
new file mode 100644
index 000000000000..28d662891937
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/components/MaterializationRunErrorCell.stories.tsx
@@ -0,0 +1,25 @@
+import type { Meta, StoryObj } from '@storybook/react'
+
+import { MaterializationRunErrorCell } from './MaterializationRunErrorCell'
+
+const meta: Meta<typeof MaterializationRunErrorCell> = {
+ title: 'Scenes-App/Data Warehouse/Materialization run error',
+ component: MaterializationRunErrorCell,
+}
+export default meta
+
+type Story = StoryObj<typeof MaterializationRunErrorCell>
+
+const FAILED_ERROR = [
+ 'ClickHouse error: Code 62. DB::Exception: Syntax error: failed at position 118 (line 4, col 5)',
+ "Unmatched parentheses: ')'",
+ 'Expected one of: token, Comma, Arrow, Dot, ClosingRoundBracket',
+].join('\n')
+
+export const FailedRun: Story = {
+ render: () => <MaterializationRunErrorCell error={FAILED_ERROR} status="Failed" />,
+}
+
+export const CompletedRunWithWarning: Story = {
+ render: () => <MaterializationRunErrorCell error="Warning: query returned no results" status="Completed" />,
+}
diff --git a/products/data_warehouse/frontend/shared/components/MaterializationRunErrorCell.test.tsx b/products/data_warehouse/frontend/shared/components/MaterializationRunErrorCell.test.tsx
new file mode 100644
index 000000000000..bb20ad374dfc
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/components/MaterializationRunErrorCell.test.tsx
@@ -0,0 +1,36 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+
+import { initKeaTests } from '~/test/init'
+import { DataModelingJobStatus } from '~/types'
+
+import { MaterializationRunErrorCell } from './MaterializationRunErrorCell'
+
+describe('MaterializationRunErrorCell', () => {
+ beforeEach(() => {
+ initKeaTests()
+ })
+
+ afterEach(cleanup)
+
+ it.each<[DataModelingJobStatus, string]>([
+ ['Failed', 'Run error'],
+ ['Skipped', 'Skip reason'],
+ ])('shows the first line in the cell and the full %s text in a dialog titled %s', async (status, title) => {
+ const error = 'ClickHouse error: Code 62\nDB::Exception: Syntax error\n at line 3'
+ render(<MaterializationRunErrorCell error={error} status={status} />)
+
+ expect(screen.getByText('ClickHouse error: Code 62')).toBeInTheDocument()
+ expect(screen.queryByText(/DB::Exception/)).not.toBeInTheDocument()
+
+ fireEvent.click(screen.getByText('View'))
+
+ expect(await screen.findByText(title)).toBeInTheDocument()
+ expect(screen.getByText(/DB::Exception: Syntax error/)).toBeInTheDocument()
+ expect(document.querySelector('[data-attr="copy-code-button"]')).toBeInTheDocument()
+
+ fireEvent.click(screen.getByText('Close'))
+ await waitFor(() => expect(screen.queryByText(title)).not.toBeInTheDocument())
+ })
+})
diff --git a/products/data_warehouse/frontend/shared/components/MaterializationRunErrorCell.tsx b/products/data_warehouse/frontend/shared/components/MaterializationRunErrorCell.tsx
new file mode 100644
index 000000000000..2b86cae2b133
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/components/MaterializationRunErrorCell.tsx
@@ -0,0 +1,66 @@
+import { CodeSnippet, Language } from 'lib/components/CodeSnippet'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
+
+import { DataModelingJobStatus } from '~/types'
+
+interface MaterializationRunErrorCellProps {
+ error: string | null
+ status: DataModelingJobStatus
+}
+
+interface RunErrorPresentation {
+ dialogTitle: string
+ copyNoun: string
+ textClass: string
+}
+
+const PRESENTATION_BY_STATUS: Record<DataModelingJobStatus, RunErrorPresentation> = {
+ Failed: { dialogTitle: 'Run error', copyNoun: 'error', textClass: 'text-danger' },
+ Completed: { dialogTitle: 'Run warning', copyNoun: 'warning', textClass: 'text-secondary' },
+ Skipped: { dialogTitle: 'Skip reason', copyNoun: 'skip reason', textClass: 'text-secondary' },
+ Cancelled: { dialogTitle: 'Cancellation reason', copyNoun: 'cancellation reason', textClass: 'text-secondary' },
+ Running: { dialogTitle: 'Run message', copyNoun: 'message', textClass: 'text-secondary' },
+}
+
+const LINES_SHOWN_BEFORE_EXPANSION = 20
+
+function openRunErrorDialog(error: string, presentation: RunErrorPresentation): void {
+ LemonDialog.open({
+ title: presentation.dialogTitle,
+ maxWidth: '40rem',
+ content: (
+ <CodeSnippet
+ language={Language.Text}
+ wrap
+ compact
+ thing={presentation.copyNoun}
+ maxLinesWithoutExpansion={LINES_SHOWN_BEFORE_EXPANSION}
+ >
+ {error}
+ </CodeSnippet>
+ ),
+ primaryButton: { children: 'Close' },
+ })
+}
+
+export function MaterializationRunErrorCell({ error, status }: MaterializationRunErrorCellProps): JSX.Element | null {
+ if (!error) {
+ return null
+ }
+ const presentation = PRESENTATION_BY_STATUS[status]
+ const firstLine = error.split('\n')[0]
+ return (
+ <div className="flex items-center gap-1 max-w-60" data-attr="materialization-run-error">
+ <span className={`truncate min-w-0 ${presentation.textClass}`}>{firstLine}</span>
+ <LemonButton
+ size="xsmall"
+ type="tertiary"
+ onClick={() => openRunErrorDialog(error, presentation)}
+ data-attr="materialization-run-error-view"
+ >
+ View
+ </LemonButton>
+ </div>
+ )
+}
diff --git a/products/data_warehouse/package.json b/products/data_warehouse/package.json
index e02175623077..29fde2dee06d 100644
--- a/products/data_warehouse/package.json
+++ b/products/data_warehouse/package.json
@@ -12,6 +12,10 @@
"kea-test-utils": "catalog:",
"posthog-js": "catalog:"
},
+ "devDependencies": {
+ "@testing-library/jest-dom": "^5.17.0",
+ "@testing-library/react": "^14.3.1"
+ },
"peerDependencies": {
"@posthog/brand": "catalog:",
"@posthog/icons": "catalog:",