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(error-tracking): guard issue status filter against out-of-enum values (#76947)

Catalinfb88f1ba3838
diff --git a/products/error_tracking/frontend/components/Indicators.tsx b/products/error_tracking/frontend/components/Indicators.tsx
index f13e9677d634..915f8a1db210 100644
--- a/products/error_tracking/frontend/components/Indicators.tsx
+++ b/products/error_tracking/frontend/components/Indicators.tsx
@@ -88,19 +88,20 @@ export const ISSUE_STATUS_CONFIG: Record<IssueStatus, IssueStatusConfig> = {
},
}
-export const IssueStatusDot = ({ status, className }: { status: IssueStatus; className?: string }): JSX.Element => {
- const config = ISSUE_STATUS_CONFIG[status] ?? UNKNOWN_STATUS_CONFIG
- return (
- <Dot
- className={clsx(
- '!border-0 !p-0 [&_[data-slot=dot-inner]]:!bg-[var(--error-tracking-status-color)]',
- className
- )}
- style={{ '--error-tracking-status-color': config.color } as React.CSSProperties}
- />
- )
+// A status can arrive from outside the enum at runtime (stale persisted filters, URL params,
+// AI-tool output, or deprecated status names), and an unguarded config lookup crashes the whole
+// scene. Render a neutral fallback instead.
+export function getIssueStatusConfig(status: IssueStatus): IssueStatusConfig {
+ return ISSUE_STATUS_CONFIG[status] ?? UNKNOWN_STATUS_CONFIG
}
+export const IssueStatusDot = ({ status, className }: { status: IssueStatus; className?: string }): JSX.Element => (
+ <Dot
+ className={clsx('!border-0 !p-0 [&_[data-slot=dot-inner]]:!bg-[var(--error-tracking-status-color)]', className)}
+ style={{ '--error-tracking-status-color': getIssueStatusConfig(status).color } as React.CSSProperties}
+ />
+)
+
interface StatusIndicatorProps {
status: IssueStatus
intent?: boolean
@@ -114,7 +115,7 @@ export const StatusIndicator = React.forwardRef<HTMLDivElement, StatusIndicatorP
{ status, size = 'small', intent = false, className, withTooltip },
ref
): JSX.Element {
- const config = ISSUE_STATUS_CONFIG[status] ?? UNKNOWN_STATUS_CONFIG
+ const config = getIssueStatusConfig(status)
const tooltip = withTooltip ? config.tooltip : undefined
const content = (
<div ref={ref} className={clsx('flex items-center', className, sizeVariants[size])}>
diff --git a/products/error_tracking/frontend/components/IssueFilteringTool.tsx b/products/error_tracking/frontend/components/IssueFilteringTool.tsx
index c7fed72d1ccf..b059c465fdc7 100644
--- a/products/error_tracking/frontend/components/IssueFilteringTool.tsx
+++ b/products/error_tracking/frontend/components/IssueFilteringTool.tsx
@@ -14,7 +14,7 @@ import type { AttachedContextItem } from 'products/posthog_ai/frontend/api/types
import { errorTrackingSceneLogic } from '../scenes/ErrorTrackingScene/errorTrackingSceneLogic'
import { TAXONOMIC_FILTER_LOGIC_KEY, TAXONOMIC_GROUP_TYPES } from './IssueFilters/consts'
import { issueFiltersLogic } from './IssueFilters/issueFiltersLogic'
-import { isValidOrderBy, issueQueryOptionsLogic } from './IssueQueryOptions/issueQueryOptionsLogic'
+import { isValidOrderBy, isValidStatus, issueQueryOptionsLogic } from './IssueQueryOptions/issueQueryOptionsLogic'
// Static instruction rendered into the trusted context block — never interpolate user or ingested data.
const ISSUES_QUERY_TOOL_CONTEXT_ITEM: AttachedContextItem = {
@@ -100,7 +100,7 @@ export function ErrorTrackingIssueFilteringTool(): JSX.Element {
if (update.orderDirection) {
setOrderDirection(update.orderDirection)
}
- if (update.status) {
+ if (update.status && isValidStatus(update.status)) {
setStatus(update.status)
}
if (update.searchQuery) {
@@ -129,7 +129,7 @@ export function ErrorTrackingIssueFilteringTool(): JSX.Element {
const applyIssuesListQuery = (input: Record<string, any>): void => {
setOrderBy(input.orderBy || 'occurrences')
setOrderDirection(input.orderDirection === 'ASC' ? 'ASC' : 'DESC')
- setStatus(input.status || 'active')
+ setStatus(isValidStatus(input.status) ? input.status : 'active')
setAssignee(input.assignee ?? null)
setDateRange(input.dateRange ?? { date_from: '-7d', date_to: null })
setFilterTestAccounts(input.filterTestAccounts === undefined ? true : !!input.filterTestAccounts)
diff --git a/products/error_tracking/frontend/components/IssueFilters/Status.tsx b/products/error_tracking/frontend/components/IssueFilters/Status.tsx
index db5e498a05ae..cd7e2e5c2435 100644
--- a/products/error_tracking/frontend/components/IssueFilters/Status.tsx
+++ b/products/error_tracking/frontend/components/IssueFilters/Status.tsx
@@ -6,7 +6,7 @@ import { Dot, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } fr
import { ErrorTrackingIssue } from '~/queries/schema/schema-general'
-import { ISSUE_STATUS_CONFIG, IssueStatusDot, LabelIndicator, StatusIndicator } from '../Indicators'
+import { IssueStatusDot, LabelIndicator, StatusIndicator, getIssueStatusConfig } from '../Indicators'
import { issueQueryOptionsLogic } from '../IssueQueryOptions/issueQueryOptionsLogic'
export type ErrorTrackingStatusSelectValue = ErrorTrackingIssue['status'] | 'all'
@@ -33,7 +33,7 @@ function quillStatusOptionLabel(key: ErrorTrackingStatusSelectValue): JSX.Elemen
return (
<span className="flex items-center gap-2">
<IssueStatusDot status={key} />
- {ISSUE_STATUS_CONFIG[key].label}
+ {getIssueStatusConfig(key).label}
</span>
)
}
diff --git a/products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic.test.ts b/products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic.test.ts
new file mode 100644
index 000000000000..93abbba6d93b
--- /dev/null
+++ b/products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic.test.ts
@@ -0,0 +1,65 @@
+import { router } from 'kea-router'
+
+import { initKeaTests } from '~/test/init'
+
+import { issueQueryOptionsLogic } from './issueQueryOptionsLogic'
+
+const LOGIC_KEY = 'test'
+const PERSISTED_STATUS_KEY = `products.error_tracking.components.IssueQueryOptions.issueQueryOptionsLogic.${LOGIC_KEY}.status`
+
+describe('issueQueryOptionsLogic', () => {
+ beforeEach(() => {
+ localStorage.clear()
+ initKeaTests()
+ })
+
+ // Values are read from persistence when the logic is built, so build after seeding localStorage
+ const mountLogic = (): ReturnType<typeof issueQueryOptionsLogic.build> => {
+ const logic = issueQueryOptionsLogic({ logicKey: LOGIC_KEY })
+ logic.mount()
+ return logic
+ }
+
+ it.each(['open', 'new', 'pending', 'pending_release', 'archived'])(
+ 'falls back to the default status when setStatus receives %p',
+ (status) => {
+ const logic = mountLogic()
+ logic.actions.setStatus(status as 'active')
+ expect(logic.values.status).toBe('active')
+ }
+ )
+
+ it.each(['all', 'resolved', 'suppressed'] as const)('applies the valid status %p', (status) => {
+ const logic = mountLogic()
+ logic.actions.setStatus(status)
+ expect(logic.values.status).toBe(status)
+ })
+
+ it('applies a valid status from the URL', () => {
+ const logic = mountLogic()
+ router.actions.push('/error_tracking', { status: 'resolved' })
+ expect(logic.values.status).toBe('resolved')
+ })
+
+ it.each([['open'], [''], [null]])(
+ 'falls back to the default when the URL has invalid status %p, overriding the persisted one',
+ (param) => {
+ localStorage.setItem(PERSISTED_STATUS_KEY, JSON.stringify('resolved'))
+ const logic = mountLogic()
+ router.actions.push('/error_tracking', { status: param })
+ expect(logic.values.status).toBe('active')
+ }
+ )
+
+ it('resets an invalid persisted status on mount', () => {
+ localStorage.setItem(PERSISTED_STATUS_KEY, JSON.stringify('open'))
+ const logic = mountLogic()
+ expect(logic.values.status).toBe('active')
+ })
+
+ it('keeps a valid persisted status on mount', () => {
+ localStorage.setItem(PERSISTED_STATUS_KEY, JSON.stringify('resolved'))
+ const logic = mountLogic()
+ expect(logic.values.status).toBe('resolved')
+ })
+})
diff --git a/products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic.ts b/products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic.ts
index 9271e20fd4aa..b57b1eeb7b3e 100644
--- a/products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic.ts
+++ b/products/error_tracking/frontend/components/IssueQueryOptions/issueQueryOptionsLogic.ts
@@ -38,6 +38,25 @@ const DEFAULT_ORDER_DIRECTION = 'DESC'
const DEFAULT_ASSIGNEE = null
const DEFAULT_STATUS = 'active'
+// The statuses the filter accepts: the query's status union minus archived/pending_release,
+// which are deprecated (writes rejected, legacy rows backfilled to resolved) and not offered by
+// the picker. Exhaustive over the rest, so removing a status from the schema fails typechecking.
+type FilterableStatus = Exclude<NonNullable<ErrorTrackingQueryStatus>, 'archived' | 'pending_release'>
+const VALID_STATUSES: Record<FilterableStatus, true> = {
+ all: true,
+ active: true,
+ resolved: true,
+ suppressed: true,
+}
+
+// Like isValidOrderBy: a persisted (localStorage), URL-provided, or tool-provided status can hold
+// a value outside the accepted set (a deprecated or renamed status, or free text produced by an
+// AI tool). Passing it through breaks the query or crashes the status filter render, so anything
+// unrecognized falls back to the default.
+export function isValidStatus(status: unknown): status is FilterableStatus {
+ return typeof status === 'string' && Object.hasOwn(VALID_STATUSES, status)
+}
+
export interface IssueQueryOptionsLogicProps {
logicKey: string
}
@@ -116,7 +135,7 @@ export const issueQueryOptionsLogic = kea<issueQueryOptionsLogicType>([
DEFAULT_STATUS as ErrorTrackingQueryStatus,
{ persist: true },
{
- setStatus: (_, { status }) => status,
+ setStatus: (_, { status }) => (isValidStatus(status) ? status : DEFAULT_STATUS),
},
],
}),
@@ -169,8 +188,12 @@ export const issueQueryOptionsLogic = kea<issueQueryOptionsLogicType>([
actions.setOrderBy(params.orderBy)
}
}
- if (params.status && !equal(params.status, values.status)) {
- actions.setStatus(params.status)
+ // Presence check rather than truthiness, since kea-router decodes `?status=` as ''
+ // and bare `?status` as null, which must also reset instead of being ignored.
+ if ('status' in params && !equal(params.status, values.status)) {
+ // Fall back to the default (which also lets actionToUrl scrub the param) so a
+ // stale link doesn't silently keep querying the previously persisted status.
+ actions.setStatus(isValidStatus(params.status) ? params.status : DEFAULT_STATUS)
}
if (params.assignee && !equal(params.assignee, values.assignee)) {
actions.setAssignee(params.assignee)
@@ -185,10 +208,13 @@ export const issueQueryOptionsLogic = kea<issueQueryOptionsLogicType>([
}),
afterMount(({ actions, values }) => {
- // The persisted orderBy is loaded straight into state (bypassing the reducer), so an
- // invalid stored value would otherwise reach the query and break the page. Reset it.
+ // Persisted orderBy/status are loaded straight into state (bypassing the reducers), so an
+ // invalid stored value would otherwise reach the query and break the page. Reset them.
if (!isValidOrderBy(values.orderBy)) {
actions.setOrderBy(DEFAULT_ORDER_BY)
}
+ if (!isValidStatus(values.status)) {
+ actions.setStatus(DEFAULT_STATUS)
+ }
}),
])