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): surface rejection reasons in code owners import errors (#70594)

posthog[bot]41f692b5e9d0
diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/assignment_rules/codeOwnersModalLogic.test.ts b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/assignment_rules/codeOwnersModalLogic.test.ts
index e068c4c586ee..236d7f750fde 100644
--- a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/assignment_rules/codeOwnersModalLogic.test.ts
+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/assignment_rules/codeOwnersModalLogic.test.ts
@@ -171,6 +171,25 @@ describe('codeOwnersModalLogic', () => {
.toMatchValues({ savingLoading: false })
expect(loadRulesSpy).toHaveBeenCalledWith(ErrorTrackingRuleType.Assignment)
- expect(lemonToast.error).toHaveBeenCalledWith('Failed to save assignment rules')
+ // The backend rejection reason is surfaced instead of a generic message, so a failed
+ // import points at the real cause.
+ expect(lemonToast.error).toHaveBeenCalledWith('Failed to save assignment rules: nope')
+ })
+
+ it('deduplicates repeated rejection reasons across failed creates', async () => {
+ silenceKeaLoadersErrors()
+ createRuleSpy.mockReset()
+ createRuleSpy.mockRejectedValue(new Error('assignee not found'))
+
+ await expectLogic(logic, () => {
+ logic.actions.setRawText('a/** @team/backend\nb/** @team/frontend')
+ logic.actions.setOwnerAssignee('@team/backend', { type: 'role', id: 'backend' })
+ logic.actions.setOwnerAssignee('@team/frontend', { type: 'role', id: 'frontend' })
+ logic.actions.saveAll()
+ })
+ .toFinishAllListeners()
+ .toMatchValues({ savingLoading: false })
+
+ expect(lemonToast.error).toHaveBeenCalledWith('Failed to save assignment rules: assignee not found')
})
})
diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/assignment_rules/codeOwnersModalLogic.ts b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/assignment_rules/codeOwnersModalLogic.ts
index 83c30ed90d16..a406042d2229 100644
--- a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/assignment_rules/codeOwnersModalLogic.ts
+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/assignment_rules/codeOwnersModalLogic.ts
@@ -29,6 +29,13 @@ export type SaveAllResult = { createdCount: number; failedCount: number; totalCo
export type CodeOwnerEntryRow = CodeOwnerRuleCandidate
export type CodeOwnerMappingRow = CodeOwnerOwnerMapping
+// Distinct, human-readable reasons behind a batch of rejected rule creations, so a failed
+// import points at the real backend cause instead of a generic string.
+function distinctRejectionReasons(reasons: unknown[]): string[] {
+ const messages = reasons.map((reason) => (reason instanceof Error ? reason.message : String(reason)))
+ return Array.from(new Set(messages.filter(Boolean)))
+}
+
export const codeOwnersModalLogic = kea<codeOwnersModalLogicType>([
path([
'products',
@@ -148,10 +155,18 @@ export const codeOwnersModalLogic = kea<codeOwnersModalLogicType>([
return api.errorTracking.createRule(ErrorTrackingRuleType.Assignment, rule)
})
)
- const failedCount = results.filter((result) => result.status === 'rejected').length
+ const rejections = results.filter(
+ (result): result is PromiseRejectedResult => result.status === 'rejected'
+ )
+ const failedCount = rejections.length
const createdCount = results.length - failedCount
if (createdCount === 0 && failedCount > 0) {
- throw new Error('Failed to save assignment rules')
+ const reasons = distinctRejectionReasons(rejections.map((rejection) => rejection.reason))
+ throw new Error(
+ reasons.length > 0
+ ? `Failed to save assignment rules: ${reasons.join('; ')}`
+ : 'Failed to save assignment rules'
+ )
}
return { createdCount, failedCount, totalCount: rows.length }
},
@@ -186,9 +201,9 @@ export const codeOwnersModalLogic = kea<codeOwnersModalLogicType>([
)
}
},
- saveAllFailure: () => {
+ saveAllFailure: ({ errorObject }) => {
rulesLogic({ ruleType: ErrorTrackingRuleType.Assignment }).actions.loadRules()
- lemonToast.error('Failed to save assignment rules')
+ lemonToast.error(errorObject instanceof Error ? errorObject.message : 'Failed to save assignment rules')
},
})),