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(customer-analytics): stop capturing expected denied-table error in opportunities tab (#66866)

posthog[bot]a5b3d1793a26
diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
index f41224764200..e2c4c6e2adbc 100644
--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md
+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
@@ -68,7 +68,7 @@ The Users tab reads its loaded data straight off `accountRelatedUsersLogic`, so
The Usage and Spend tabs render existing saved billing insights — **point users to them, don't rebuild billing as new insights.**
-The Opportunities tab lists the account's Salesforce opportunities from the data-warehouse `salesforce.opportunity` table (joined by the account's `sfdc_id`). The query runs in `accountOpportunitiesLogic` rather than via a bare `<Query>` so the tab owns every state: a missing `sfdc_id` shows a "not linked to Salesforce" empty state, and because `salesforce.opportunity` is **production-only**, a failed query degrades to a pretty hog empty state (the error is still captured to PostHog) instead of a red error box. Each opportunity name links to its Salesforce record (`SALESFORCE_ORIGIN/<id>` in `constants.ts`, the same origin the Useful links sidebar uses).
+The Opportunities tab lists the account's Salesforce opportunities from the data-warehouse `salesforce.opportunity` table (joined by the account's `sfdc_id`). The query runs in `accountOpportunitiesLogic` rather than via a bare `<Query>` so the tab owns every state: a missing `sfdc_id` shows a "not linked to Salesforce" empty state, and because `salesforce.opportunity` is **access-gated and production-only**, a failed query degrades to a pretty hog empty state instead of a red error box. The expected denied/absent-table `QueryError` (`You don't have access to table …` / `Unknown table …`) is **not** captured to PostHog — it's the normal empty state, not a bug — while genuine, unexpected query failures are still reported (`isExpectedMissingTableError` in `accountOpportunitiesLogic`). Each opportunity name links to its Salesforce record (`SALESFORCE_ORIGIN/<id>` in `constants.ts`, the same origin the Useful links sidebar uses).
Clicking a note in the Notes tab opens it in the global notebook **side panel** (`notebookPanelLogic.selectNotebook`), keeping the Accounts list mounted — not the full `NotebookScene`. The note `<Link>` still points at `urls.notebook(shortId)` so cmd/ctrl-click opens the full page in a new tab; a plain click `preventDefault()`s the router push and opens the panel instead.
diff --git a/products/customer_analytics/frontend/components/Accounts/accountOpportunitiesLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountOpportunitiesLogic.test.ts
index a37df214be95..8b278f70397c 100644
--- a/products/customer_analytics/frontend/components/Accounts/accountOpportunitiesLogic.test.ts
+++ b/products/customer_analytics/frontend/components/Accounts/accountOpportunitiesLogic.test.ts
@@ -58,13 +58,27 @@ describe('accountOpportunitiesLogic', () => {
expect(queryMock).not.toHaveBeenCalled()
})
- it('degrades to a null result instead of throwing when the warehouse query fails', async () => {
+ it.each([
+ ['access is denied', "You don't have access to table `salesforce.opportunity`."],
+ ['the table is absent', 'Unknown table `salesforce.opportunity`.'],
+ ])('degrades to a null result without capturing the expected error when %s', async (_label, message) => {
mockAccountsRetrieve.mockResolvedValue(buildAccount({ sfdc_id: 'sfdc-1' }))
- jest.spyOn(api, 'query').mockRejectedValue(new Error('Unknown table salesforce.opportunity'))
+ jest.spyOn(api, 'query').mockRejectedValue(new Error(message))
await mount()
expect(logic.values.opportunitiesResult).toEqual({ sfdcId: 'sfdc-1', opportunities: null })
+ expect(posthog.captureException).not.toHaveBeenCalled()
+ })
+
+ it('still captures genuine, unexpected warehouse query failures', async () => {
+ mockAccountsRetrieve.mockResolvedValue(buildAccount({ sfdc_id: 'sfdc-1' }))
+ jest.spyOn(api, 'query').mockRejectedValue(new Error('Query exceeded memory limit'))
+
+ await mount()
+
+ expect(logic.values.opportunitiesResult).toEqual({ sfdcId: 'sfdc-1', opportunities: null })
+ expect(posthog.captureException).toHaveBeenCalledTimes(1)
})
it('maps warehouse rows to opportunities preserving column order and nulls', async () => {
diff --git a/products/customer_analytics/frontend/components/Accounts/accountOpportunitiesLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountOpportunitiesLogic.ts
index 4b342bf9ac97..b51c683c03b6 100644
--- a/products/customer_analytics/frontend/components/Accounts/accountOpportunitiesLogic.ts
+++ b/products/customer_analytics/frontend/components/Accounts/accountOpportunitiesLogic.ts
@@ -38,6 +38,16 @@ export interface AccountOpportunitiesResult {
// Identity used as a "not loaded yet" sentinel by the view — every loaded outcome returns a fresh object.
export const NOT_LOADED: AccountOpportunitiesResult = { sfdcId: null, opportunities: null }
+const OPPORTUNITY_TABLE = 'salesforce.opportunity'
+
+const isExpectedMissingTableError = (error: unknown): boolean => {
+ const message = error instanceof Error ? error.message : String(error ?? '')
+ return (
+ message.includes(OPPORTUNITY_TABLE) &&
+ (message.includes("don't have access to table") || message.includes('Unknown table'))
+ )
+}
+
export const accountOpportunitiesLogic = kea<accountOpportunitiesLogicType>([
path((key) => ['scenes', 'customerAnalytics', 'accounts', 'accountOpportunitiesLogic', key]),
props({} as AccountOpportunitiesLogicProps),
@@ -85,11 +95,11 @@ export const accountOpportunitiesLogic = kea<accountOpportunitiesLogicType>([
}))
return { sfdcId, opportunities }
} catch (error) {
- // `salesforce.opportunity` only exists in production. Elsewhere (and on genuine failures,
- // which we still report) we degrade to the empty state instead of a red query-error box.
- posthog.captureException(error as Error, {
- scope: 'accountOpportunitiesLogic.loadOpportunities',
- })
+ if (!isExpectedMissingTableError(error)) {
+ posthog.captureException(error as Error, {
+ scope: 'accountOpportunitiesLogic.loadOpportunities',
+ })
+ }
return { sfdcId, opportunities: null }
}
},