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(cohorts): surface load errors instead of empty state on list pages (#63151)

posthog[bot]c3e0fdc7f504
diff --git a/frontend/src/queries/nodes/DataTable/DataTable.tsx b/frontend/src/queries/nodes/DataTable/DataTable.tsx
index 0be22328771a..595b7669ef1c 100644
--- a/frontend/src/queries/nodes/DataTable/DataTable.tsx
+++ b/frontend/src/queries/nodes/DataTable/DataTable.tsx
@@ -181,6 +181,7 @@ export function DataTable({
highlightedRows,
backToSourceQuery,
} = useValues(dataNodeLogic(dataNodeLogicProps))
+ const { loadData } = useActions(dataNodeLogic(dataNodeLogicProps))
const canUseWebAnalyticsPreAggregatedTables = useFeatureFlag('SETTINGS_WEB_ANALYTICS_PRE_AGGREGATED_TABLES')
const hasCustomerAnalyticsEnabled = useFeatureFlag('CUSTOMER_ANALYTICS')
@@ -923,6 +924,7 @@ export function DataTable({
<InsightErrorState
query={query}
excludeDetail
+ onRetry={() => loadData('force_blocking')}
title={
queryCancelled
? 'The query was cancelled'
@@ -932,7 +934,10 @@ export function DataTable({
}
/>
) : (
- <InsightErrorState query={query} />
+ <InsightErrorState
+ query={query}
+ onRetry={() => loadData('force_blocking')}
+ />
)
) : (
<InsightEmptyState
diff --git a/frontend/src/scenes/cohorts/Cohorts.tsx b/frontend/src/scenes/cohorts/Cohorts.tsx
index 4d09721cd93e..9940b4c28052 100644
--- a/frontend/src/scenes/cohorts/Cohorts.tsx
+++ b/frontend/src/scenes/cohorts/Cohorts.tsx
@@ -3,7 +3,7 @@ import './Cohorts.scss'
import { useActions, useValues } from 'kea'
import { combineUrl, router } from 'kea-router'
-import { LemonDialog, LemonInput, LemonSelect } from '@posthog/lemon-ui'
+import { LemonBanner, LemonDialog, LemonInput, LemonSelect } from '@posthog/lemon-ui'
import { AppShortcut } from 'lib/components/AppShortcuts/AppShortcut'
import { keyBinds } from 'lib/components/AppShortcuts/shortcuts'
@@ -37,9 +37,17 @@ export const scene: SceneExport = {
}
export function Cohorts(): JSX.Element {
- const { cohorts, cohortsLoading, pagination, cohortFilters, shouldShowEmptyState, cohortSorting } =
- useValues(cohortsSceneLogic)
- const { deleteCohort, exportCohortPersons, setCohortFilters, setCohortSorting } = useActions(cohortsSceneLogic)
+ const {
+ cohorts,
+ cohortsLoading,
+ pagination,
+ cohortFilters,
+ shouldShowEmptyState,
+ cohortSorting,
+ cohortsLoadError,
+ } = useValues(cohortsSceneLogic)
+ const { deleteCohort, exportCohortPersons, setCohortFilters, setCohortSorting, loadCohorts } =
+ useActions(cohortsSceneLogic)
const { searchParams } = useValues(router)
const columns: LemonTableColumns<CohortType> = [
@@ -295,6 +303,13 @@ export function Cohorts(): JSX.Element {
pagination={pagination}
dataSource={cohorts.results}
nouns={['cohort', 'cohorts']}
+ emptyState={
+ cohortsLoadError ? (
+ <LemonBanner type="error" action={{ children: 'Try again', onClick: () => loadCohorts() }}>
+ There was an error loading cohorts: {cohortsLoadError}
+ </LemonBanner>
+ ) : undefined
+ }
data-attr="cohorts-table"
sorting={cohortSorting}
onSort={(sorting) => {
diff --git a/frontend/src/scenes/cohorts/cohortsSceneLogic.test.ts b/frontend/src/scenes/cohorts/cohortsSceneLogic.test.ts
index 20c25368ea19..904b732c16b7 100644
--- a/frontend/src/scenes/cohorts/cohortsSceneLogic.test.ts
+++ b/frontend/src/scenes/cohorts/cohortsSceneLogic.test.ts
@@ -188,5 +188,39 @@ describe('cohortsSceneLogic', () => {
expect(logic.values.shouldShowEmptyState).toBe(false)
})
})
+
+ describe('load errors', () => {
+ it.each([
+ ['detail from the error object', { detail: 'Unknown table `person`' }, 'Unknown table `person`'],
+ ['the error string when there is no detail', {}, 'Internal server error'],
+ ['the default message when detail is undefined', { detail: undefined }, 'Error loading cohorts'],
+ ])('tracks %s', async (_, errorObject, expected) => {
+ router.actions.push(urls.cohorts())
+ await expectLogic(logic).toDispatchActions(['loadCohortsSuccess'])
+ expect(logic.values.cohortsLoadError).toBe(null)
+
+ logic.actions.loadCohortsFailure('Internal server error', errorObject)
+ expect(logic.values.cohortsLoadError).toBe(expected)
+ })
+
+ it('suppresses the empty state while there is a load error', async () => {
+ router.actions.push(urls.cohorts())
+ await expectLogic(logic).toDispatchActions(['loadCohortsSuccess'])
+
+ logic.actions.loadCohortsFailure('Internal server error', { detail: 'Unknown table `person`' })
+ expect(logic.values.shouldShowEmptyState).toBe(false)
+ })
+
+ it('clears the error when retrying the load', async () => {
+ router.actions.push(urls.cohorts())
+ await expectLogic(logic).toDispatchActions(['loadCohortsSuccess'])
+
+ logic.actions.loadCohortsFailure('Internal server error', { detail: 'Unknown table `person`' })
+ expect(logic.values.cohortsLoadError).toBe('Unknown table `person`')
+
+ logic.actions.loadCohorts()
+ expect(logic.values.cohortsLoadError).toBe(null)
+ })
+ })
})
})
diff --git a/frontend/src/scenes/cohorts/cohortsSceneLogic.ts b/frontend/src/scenes/cohorts/cohortsSceneLogic.ts
index d2093b472bf5..7ce8fbdc4642 100644
--- a/frontend/src/scenes/cohorts/cohortsSceneLogic.ts
+++ b/frontend/src/scenes/cohorts/cohortsSceneLogic.ts
@@ -84,6 +84,43 @@ export const cohortsSceneLogic = kea<cohortsSceneLogicType>([
},
],
}),
+ loaders(({ values }) => ({
+ cohorts: [
+ {
+ count: 0,
+ results: [],
+ filters: DEFAULT_COHORT_FILTERS,
+ offset: 0,
+ } as CountedPaginatedResponse<CohortType>,
+ {
+ loadCohorts: async () => {
+ const response = await api.cohorts.listPaginated({
+ ...values.paramsFromFilters,
+ })
+ personsLogic.findMounted({ syncWithUrl: true })?.actions.loadCohorts()
+ return {
+ count: response.count,
+ results: response.results.map((cohort) => processCohort(cohort)),
+ }
+ },
+ },
+ ],
+ })),
+ reducers({
+ cohortsLoadError: [
+ null as string | null,
+ {
+ loadCohorts: () => null,
+ loadCohortsSuccess: () => null,
+ loadCohortsFailure: (_, { error, errorObject }) => {
+ if (errorObject && 'detail' in errorObject) {
+ return errorObject.detail ?? 'Error loading cohorts'
+ }
+ return error ?? 'Error loading cohorts'
+ },
+ },
+ ],
+ }),
selectors({
breadcrumbs: [
() => [],
@@ -125,34 +162,18 @@ export const cohortsSceneLogic = kea<cohortsSceneLogicType>([
},
],
shouldShowEmptyState: [
- (s) => [s.cohorts, s.cohortFilters],
- (cohorts: CountedPaginatedResponse<CohortType>, filters: CohortFilters): boolean => {
- return cohorts.results.length === 0 && objectsEqual(filters, DEFAULT_COHORT_FILTERS)
+ (s) => [s.cohorts, s.cohortFilters, s.cohortsLoadError],
+ (
+ cohorts: CountedPaginatedResponse<CohortType>,
+ filters: CohortFilters,
+ cohortsLoadError: string | null
+ ): boolean => {
+ return (
+ !cohortsLoadError && cohorts.results.length === 0 && objectsEqual(filters, DEFAULT_COHORT_FILTERS)
+ )
},
],
}),
- loaders(({ values }) => ({
- cohorts: [
- {
- count: 0,
- results: [],
- filters: DEFAULT_COHORT_FILTERS,
- offset: 0,
- } as CountedPaginatedResponse<CohortType>,
- {
- loadCohorts: async () => {
- const response = await api.cohorts.listPaginated({
- ...values.paramsFromFilters,
- })
- personsLogic.findMounted({ syncWithUrl: true })?.actions.loadCohorts()
- return {
- count: response.count,
- results: response.results.map((cohort) => processCohort(cohort)),
- }
- },
- },
- ],
- })),
listeners(({ actions, cache, values }) => ({
loadCohortsSuccess: async ({ cohorts }: { cohorts: CountedPaginatedResponse<CohortType> }) => {
const is_calculating = cohorts.results.filter((cohort) => cohort.is_calculating).length > 0