fix(#828): preserve GitHub error body and status in mint errors - #856
fix(#828): preserve GitHub error body and status in mint errors#856fullsend-ai-coder[bot] wants to merge 2 commits into
Conversation
GitHub API error responses were discarded with io.Copy(io.Discard, ...) and all upstream failures were collapsed to HTTP 502 (Bad Gateway), making mint token failures impossible to debug from GitHub Actions logs. - Add GitHubAPIError type that preserves the upstream status code and response body from GitHub API calls - Read the response body (size-limited to 4096 bytes) instead of discarding it, so GitHub's error message appears in mint service logs - Forward GitHub 4xx status codes to the client instead of collapsing them to 502, allowing clients to distinguish retriable (5xx) from non-retriable (4xx) errors - Apply consistently to FindInstallation, FindOrgInstallation, GetOrgVariable, createInstallationTokenWithPermissions, and CreateInstallationToken - Sync embed copies for GCF deployment Closes #828
|
🤖 Finished Review · ✅ Success · Started 9:05 AM UTC · Completed 9:20 AM UTC |
ReviewFindingsLow
Previous runReviewFindingsMedium
Low
Labels: PR fixes a confirmed defect in mint error handling (issue #828), matching the type/bug label convention used for bug fixes in this repo. |
|
/fs-fix |
|
🤖 Finished Fix · ✅ Success · Started 10:31 AM UTC · Completed 10:38 AM UTC |
- Use upstreamStatus(err) in mintTokenCrossOrg so cross-org mints forward GitHub 4xx instead of collapsing all errors to 502 - Change fetchForeignAllowlist's FindOrgInstallation wrapping from %v to %w so errors.As can find the GitHubAPIError through the chain - Fix readErrorBody docstring that incorrectly claimed it drains remaining bytes - Sync embed copies Addresses review feedback on #856
🔧 Fix agent — iteration 1 (human-triggered)Fixed 2 code issues and 1 docstring issue from the review. Applied upstreamStatus(err) in mintTokenCrossOrg and changed %v to %w in fetchForeignAllowlist so the GitHubAPIError chain is preserved for cross-org mints. Fixed readErrorBody docstring accuracy. All changes synced to embed copies. Disagreed with 2 informational findings (data-exposure is intentional per #828, partial-scope is a tracking note). Fixed (4):
Disagreed (2):
Tests: passedNext steps:
|
|
🤖 Finished Review · ✅ Success · Started 10:40 AM UTC · Completed 10:59 AM UTC |
|
This pull request has been automatically marked as stale because it has not had any activity in the last month. It will be closed in 2 weeks if no further activity occurs. Remove the |
Summary
Preserves GitHub's error response body and status code in mint token failures instead of discarding the body and collapsing all upstream errors to 502. This makes mint failures debuggable from GitHub Actions logs (where maintainers look first) rather than requiring direct access to Cloud Run logs.
Related Issue
Fixes #828
Changes
GitHubAPIErrortype ininternal/mintcore/github.gothat preserves the upstream HTTP status code and response bodyio.Copy(io.Discard, ...)withreadErrorBody()in all five GitHub API call sites (FindInstallation,FindOrgInstallation,GetOrgVariable,createInstallationTokenWithPermissions,CreateInstallationToken)upstreamStatus()helper inhandler.gothat forwards 4xx from GitHub as-is (non-retriable client errors) and returns 502 only for 5xx/network errorsgithub.go.embed,handler.go.embed) for GCF deploymentTesting
TestCreateInstallationToken_NonCreatedStatus_IncludesBody— verifies 422 body is preservedTestCreateInstallationToken_5xxStatus_IncludesBody— verifies 500 body is preservedTestFindInstallation_ErrorIncludesBody— verifies 403 body is preservedTestHandler_GitHubTokenCreation422_ForwardedAsIs— verifies handler forwards 422 instead of 502TestHandler_GitHub5xx_Returns502— verifies 5xx still returns 502TestHandler_InstallationNotFound— updated to expect 404 (was 502)Checklist
!for breaking changes)Closes #828
Post-script verification
agent/828-mint-error-propagation)c887fc47c59d8b87b5282ca44044d2933d30df41..HEAD)