fix: split DB errors from ErrNotFound in OIDC link handlers#191
Merged
Conversation
Agent-Logs-Url: https://github.com/amalgamated-tools/goauth/sessions/8d76aa85-f607-4faf-95ff-ef15d2364b8e Co-authored-by: veverkap <22348+veverkap@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
veverkap
May 3, 2026 14:26
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves observability and correctness in the OIDC account-linking flow by distinguishing “not found” from transient/unknown store errors, avoiding user-facing “not found” redirects that mask backend failures.
Changes:
- In
handleLinkCallback, branch onerrors.Is(err, auth.ErrNotFound)forFindByID, and log + redirect a distinct message on non-ErrNotFounderrors. - In
handleLinkCallback, log failures fromLinkOIDCSubjectbefore redirecting. - In
Link, split the combinederr != nil || u.OIDCSubject != nilcheck into explicit branches, logging and returning500on non-ErrNotFoundstore errors.
Show a summary per file
| File | Description |
|---|---|
handler/oidc.go |
Separates ErrNotFound from DB/store errors in OIDC linking paths and adds error logging for better operational visibility. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
…k handlers Cover the non-ErrNotFound FindByID path in handleLinkCallback (should redirect with Link verification failed) and in Link (should return 500, not 409).
Kept our ErrNotFound→409 / other-errors→500 split in Link(); reverted TestOIDCLink_userNotFound to expect 409 (StatusConflict) to match.
github-actions Bot
added a commit
that referenced
this pull request
May 3, 2026
… split - 'User not found' now correctly reflects only ErrNotFound from FindByID - 'Link verification failed' now covers both FindByID and FindByOIDCSubject DB errors - Warning block updated to mention both guard paths - HTTP status table: Link 409 limited to ErrNotFound; Link 500 now includes FindByID DB errors Reflects fix in #191. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
veverkap
pushed a commit
that referenced
this pull request
May 3, 2026
… split (#197) - 'User not found' now correctly reflects only ErrNotFound from FindByID - 'Link verification failed' now covers both FindByID and FindByOIDCSubject DB errors - Warning block updated to mention both guard paths - HTTP status table: Link 409 limited to ErrNotFound; Link 500 now includes FindByID DB errors Reflects fix in #191. Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three places in
handler/oidc.gosilently redirected users with user-facing "not found" messages on transient DB errors, masking failures with no log output.Changes
handleLinkCallback–FindByID: branch onerrors.Is(err, auth.ErrNotFound)— not-found → redirect"User not found"; other errors →slog.ErrorContext+ redirect"Link verification failed"handleLinkCallback–LinkOIDCSubject: addslog.ErrorContextbefore"Failed to link"redirect so store failures are observableLink–FindByID: decomposeerr != nil || u.OIDCSubject != nilinto three explicit branches — DB error → log + 500;ErrNotFound→ 409; already-linked → 409Greptile Summary
This PR correctly separates transient DB errors from
ErrNotFoundin three OIDC link handler code paths, addingslog.ErrorContextlogging for previously silent failures. The logic and test additions are sound, with one minor semantic concern in theLinkhandler where a not-found user returns the same409 "cannot link account"as an already-linked user, making the two conditions indistinguishable to API clients.Confidence Score: 5/5
Safe to merge; all slog calls include context and error handling logic is correct — one P2 semantic nit on the 409 status for ErrNotFound
Only P2 findings present; the core error-splitting logic is correct, logging is properly instrumented with context, and new tests cover all new branches
handler/oidc.go lines 319–320 (409 vs 404 for ErrNotFound in Link handler)
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[handleLinkCallback / Link called] --> B[FindByID] B --> C{err?} C -- "errors.Is(ErrNotFound)" --> D[Redirect: User not found / 409 Conflict] C -- "other DB error" --> E[slog.ErrorContext\nRedirect: Link verification failed / 500] C -- nil --> F{OIDCSubject set?} F -- yes --> G[Redirect: Already linked / 409 Conflict] F -- no --> H[Continue OIDC flow] H --> I[LinkOIDCSubject] I --> J{err?} J -- yes --> K[slog.ErrorContext\nRedirect: Failed to link] J -- no --> L[Redirect: oidc_linked=true]Prompt To Fix All With AI
Reviews (3): Last reviewed commit: "chore: merge origin/main and resolve con..." | Re-trigger Greptile