Skip to content

refactor(user): filter account linking errors in Sentry - #5078

Merged
eshurakov merged 1 commit into
mainfrom
session/agent_4379a44f-b8c5-4f57-8bab-f1f1bd86b278
Aug 6, 2026
Merged

eshurakov merged 1 commit into
mainfrom
session/agent_4379a44f-b8c5-4f57-8bab-f1f1bd86b278

Conversation

@eshurakov

Copy link
Copy Markdown
Contributor

Summary

linkAccountToExistingUser reported every account-linking failure to Sentry via captureException, including expected user errors like ACCOUNT-ALREADY-LINKED (user tried to link a provider account already attached to another Kilo user) and PROVIDER-ALREADY-LINKED. This produced noisy Sentry issues such as GET /api/auth/callback/githubAccount linking failed: ACCOUNT-ALREADY-LINKED.

The NextAuth signIn handler in server.ts already treats these codes as expected and skips Sentry, but the capture in linkAccountToExistingUser fired unconditionally before that check. This PR guards the captureException so only LINKING-FAILED (a genuine system error — the DB insert returned nothing) is reported. Expected errors still return normally and redirect the user to the appropriate error page.

Verification

  • No manual testing performed — change is a conditional guard around an existing Sentry call; oxlint passes (0 warnings, 0 errors) and existing multi-auth.test.ts coverage of linkAuthProviderToUser error codes is unaffected. Full web typecheck could not complete within the CI-agent sandbox time limit.

Visual Changes

N/A

Reviewer Notes

linkAuthProviderToUser returns exactly three failure codes (ACCOUNT-ALREADY-LINKED, PROVIDER-ALREADY-LINKED, LINKING-FAILED), so the === 'LINKING-FAILED' guard covers all unexpected cases.

Only report 'LINKING-FAILED' errors to Sentry. Expected user errors
such as 'ACCOUNT-ALREADY-LINKED' and 'PROVIDER-ALREADY-LINKED' are
now suppressed to reduce noise in error monitoring.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
@kilo-code-bot

kilo-code-bot Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The Sentry-noise guard around captureException in linkAccountToExistingUser is correct, type-safe, and consistent with the existing expected-error handling in the NextAuth signIn handler.

Files Reviewed (1 file)
  • apps/web/src/lib/user/index.ts

Verification notes: Confirmed against current HEAD (0217c93) that linkAuthProviderToUser returns exactly the three failure codes ACCOUNT-ALREADY-LINKED, PROVIDER-ALREADY-LINKED, and LINKING-FAILED (see LinkAuthErrors type), so the === 'LINKING-FAILED' guard suppresses only expected user errors while still reporting genuine system failures. Both callers (createOrUpdateUser auto-link path and the signIn account-linking flow) propagate the returned codes to server.ts, which already treats the two expected codes as non-Sentry errors and redirects the user — behavior is preserved. Error return values, redirect flow, and existing test coverage are unaffected.


Reviewed by kimi-k3 · Input: 35.5K · Output: 4.5K · Cached: 200.7K

Review guidance: REVIEW.md from base branch main

@eshurakov
eshurakov merged commit 327df2b into main Aug 6, 2026
16 checks passed
@eshurakov
eshurakov deleted the session/agent_4379a44f-b8c5-4f57-8bab-f1f1bd86b278 branch August 6, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants