Conversation
The old code didn't handle transient errors from github like 502, causing syncs to fail and start over.
📝 WalkthroughWalkthroughModified error handling in the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
|
Claude finished @ggreer's task in 2m 2s —— View job PR Review: Fix user list error handlingIssues: 0 Breaking ChangesNone. IssuesNone found. The refactoring correctly replaces inline error handling with the centralized
The log level change from DocumentationUp to date — no capabilities, config, or credential changes. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/connector/user.go`:
- Around line 156-160: The code currently returns an error for any non-404
response in the GetByID handling (calling wrapGitHubError), which aborts sync on
transient GitHub failures; add a helper isTransientGitHubError(resp
*github.Response) that returns true for 502, 503, 504 and, in the block where
isNotFoundError(res) is checked, treat transient responses the same as not-found
by assigning u = user instead of returning; only call wrapGitHubError and return
for truly non-recoverable responses. Ensure you reference the existing
isNotFoundError(res) and wrapGitHubError(err, res, "...") symbols when making
the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3098cae1-5797-418d-81ea-ad7236c53fef
📒 Files selected for processing (1)
pkg/connector/user.go
| if isNotFoundError(res) { | ||
| l.Warn("error fetching user by id", zap.Error(err), zap.Int64("user_id", user.GetID())) | ||
| u = user | ||
| } else { | ||
| return nil, nil, wrapGitHubError(err, res, "github-connector: failed to get user by id") |
There was a problem hiding this comment.
Treat transient GetByID errors as recoverable too
At Line 160, non-404 errors still abort the sync. That means transient GitHub failures (e.g., 502/503/504) can still restart the operation, which conflicts with this PR’s objective. Consider falling back to u = user for transient HTTP errors as well, and only returning on non-recoverable failures.
Proposed fix
u, res, err := o.client.Users.GetByID(ctx, user.GetID())
if err != nil {
// This undocumented API can return 404 for some users. If this fails it means we won't get some of their details like email
- if isNotFoundError(res) {
+ if isNotFoundError(res) || isTransientGitHubError(res) {
l.Warn("error fetching user by id", zap.Error(err), zap.Int64("user_id", user.GetID()))
u = user
} else {
return nil, nil, wrapGitHubError(err, res, "github-connector: failed to get user by id")
}
}func isTransientGitHubError(resp *github.Response) bool {
if resp == nil {
return false
}
switch resp.StatusCode {
case 502, 503, 504:
return true
default:
return false
}
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pkg/connector/user.go` around lines 156 - 160, The code currently returns an
error for any non-404 response in the GetByID handling (calling
wrapGitHubError), which aborts sync on transient GitHub failures; add a helper
isTransientGitHubError(resp *github.Response) that returns true for 502, 503,
504 and, in the block where isNotFoundError(res) is checked, treat transient
responses the same as not-found by assigning u = user instead of returning; only
call wrapGitHubError and return for truly non-recoverable responses. Ensure you
reference the existing isNotFoundError(res) and wrapGitHubError(err, res, "...")
symbols when making the change.
There was a problem hiding this comment.
wrapGitHubError() returns codes.Unavailable for 502/503/etc, which causes syncer to retry the List() call.
There was a problem hiding this comment.
@ggreer, thanks for the clarification! That makes sense — since wrapGitHubError() maps 502/503/504 responses to codes.Unavailable, the syncer will automatically retry the List() call rather than treating it as a fatal failure or restarting the entire sync from scratch. The current approach is correct and the concern I raised doesn't apply here.
✏️ Learnings added
Learnt from: ggreer
Repo: ConductorOne/baton-github PR: 127
File: pkg/connector/user.go:156-160
Timestamp: 2026-03-05T21:28:54.578Z
Learning: In the `baton-github` connector (`pkg/connector/user.go`), `wrapGitHubError()` returns `codes.Unavailable` for transient HTTP errors (502, 503, 504 etc.), which causes the syncer to retry the `List()` call rather than aborting or restarting the full sync. This means returning `wrapGitHubError(err, res, ...)` for non-404 errors in `GetByID` is intentional and correct — transient errors are already handled via the retry mechanism.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
The old code didn't handle transient errors from github like 502, causing syncs to fail and start over.
Summary by CodeRabbit