Repository navigation
Use GitHub API error helper for remaining REST failure paths - #4029
Open
basil-k-aji-dev wants to merge 1 commit into
Open
basil-k-aji-dev wants to merge 1 commit into
basil-k-aji-dev wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the API error-handling changes.
No open issues 🎉
What changed in this PR
Standardizes REST API failure handling across nine tools, addressing #4028 by recording errors for middleware and preserving rate-limit retry guidance without changing tool schemas.
Changes:
- Routes affected API failures through
NewGitHubAPIErrorResponse. - Updates existing tests to expect tool error results.
- Adds shared coverage for 404 and primary rate-limit responses.
| File | Description |
|---|---|
pkg/github/security_advisories.go |
Uses the helper in four advisory tools. |
pkg/github/security_advisories_test.go |
Updates advisory error assertions. |
pkg/github/search_utils.go |
Uses the helper for pull-request search failures. |
pkg/github/repositories.go |
Uses the helper for release-list and latest-release failures. |
pkg/github/repositories_test.go |
Updates release error assertions. |
pkg/github/issues.go |
Uses the helper for issue search and owner-level issue types. |
pkg/github/api_error_helper_test.go |
Tests error text and recording across ten tools, including a control. |
Review effort: Balanced (adaptive)
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.
Summary
Route the GitHub API failure paths of nine tools through
ghErrors.NewGitHubAPIErrorResponse, matchinglist_tagsandlist_branchesanddocs/error-handling.md.Why
Fixes #4028
These paths returned plain errors, so the failure was never recorded for middleware and rate-limit responses lost the "Retry after" message. For example, with a rate-limited response
list_releasesreturnedfailed to list releases: GET ...: 403 API rate limit exceeded [rate reset in 60m00s], whilelist_tagsreturnsfailed to list tags: GitHub API rate limit exceeded. Retry after 1h0m0s.What changed
list_releases,get_latest_release: use the helper on API failurelist_global_security_advisories,list_repository_security_advisories,get_global_security_advisory,list_org_repository_security_advisories: samesearch_issues,search_pull_requests,list_issue_types(owner-only path; the repo path already used the helper): sameTest_RESTAPIFailuresUseGitHubAPIErrorResponsecovering the nine tools pluslist_tagsas a control, each with a 404 and a primary rate limit, asserting the tool error text and the recordedGitHubAPIError. Without the change it fails for all nine tools and passes forlist_tags.Test_ListReleases/releases_list_fails,Test_GetLatestRelease/latest_release_fetch_fails,Test_ListGlobalSecurityAdvisories/{invalid_severity_value,API_error_handling},Test_GetGlobalSecurityAdvisory/{invalid_ghsaId_format,advisory_not_found},Test_ListRepositorySecurityAdvisories/advisories_listing_fails,Test_ListOrgRepositorySecurityAdvisories/listing_fails. The two with "invalid" in their names are mocked API 400 responses, not local validation, so they belong on this path. The typed handlers already turned a returned error into anIsErrortool result, so clients saw a tool error before as well.MCP impact
No schema change. API failures are now recorded for middleware, rate limits read "GitHub API rate limit exceeded. Retry after ...", and 422 details are formatted like other tools.
Prompts tested (tool changes only)
Not run against a live client. Covered by mocked 404 and 403 rate-limit responses for each tool, for example "List the releases in owner/repo" while rate limited. A transport error with no HTTP response was also probed for all nine tools and returns a tool error with no panic.
Security / limits
Tool renaming
Lint & tests
./script/lint./script/testgo test -count=1 ./...,go vet ./pkg/...andgofmt -lpass (32 packages, no failures, same asmain)../script/lintwas not run (no golangci-lint available offline), and the-racerun in./script/testwas not run because the race detector is unsupported on my ARM host. Each of the nine swaps was reverted individually and caught by the new test.Docs
No toolsnap or README changes;
generate-docsleaves the tree unchanged.Skills
Other REST sites that still bypass the helper (
issue_read get,GetIssueComments,create_branchGetRef, a few inrepositories_helper.go, job logs) are left for a follow-up to keep this to one concern. Open #3580 (get_global_security_advisory) and draft #3832 (list_issue_typesorg path) edit lines this touches, so whichever lands second needs a small rebase; #3543 would extend its new_metato these sites.