Skip to content

Use GitHub API error helper for remaining REST failure paths - #4029

Open
basil-k-aji-dev wants to merge 1 commit into
github:mainfrom
basil-k-aji-dev:fix/api-error-helper
Open

basil-k-aji-dev wants to merge 1 commit into
github:mainfrom
basil-k-aji-dev:fix/api-error-helper

Conversation

@basil-k-aji-dev

Copy link
Copy Markdown

Summary

Route the GitHub API failure paths of nine tools through ghErrors.NewGitHubAPIErrorResponse, matching list_tags and list_branches and docs/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_releases returned failed to list releases: GET ...: 403 API rate limit exceeded [rate reset in 60m00s], while list_tags returns failed to list tags: GitHub API rate limit exceeded. Retry after 1h0m0s.

What changed

  • list_releases, get_latest_release: use the helper on API failure
  • list_global_security_advisories, list_repository_security_advisories, get_global_security_advisory, list_org_repository_security_advisories: same
  • search_issues, search_pull_requests, list_issue_types (owner-only path; the repo path already used the helper): same
  • New table test Test_RESTAPIFailuresUseGitHubAPIErrorResponse covering the nine tools plus list_tags as a control, each with a 404 and a primary rate limit, asserting the tool error text and the recorded GitHubAPIError. Without the change it fails for all nine tools and passes for list_tags.
  • Eight existing subtests now assert a tool error result instead of a handler error: 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 an IsError tool result, so clients saw a tool error before as well.

MCP impact

  • Tool schema or behavior changed

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

  • No security or limits impact

Tool renaming

  • I am not renaming tools as part of this PR

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

go test -count=1 ./..., go vet ./pkg/... and gofmt -l pass (32 packages, no failures, same as main). ./script/lint was not run (no golangci-lint available offline), and the -race run in ./script/test was 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

  • Not needed

No toolsnap or README changes; generate-docs leaves the tree unchanged.

Skills

  • Updated relevant skills or confirmed no bundled skill applies

Other REST sites that still bypass the helper (issue_read get, GetIssueComments, create_branch GetRef, a few in repositories_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_types org path) edit lines this touches, so whichever lands second needs a small rebase; #3543 would extend its new _meta to these sites.

@basil-k-aji-dev
basil-k-aji-dev requested a review from a team as a code owner December 4, 2026 14:26
Copilot AI adaptive review requested due to automatic review settings December 4, 2026 14:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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)

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.

Tool error paths skip NewGitHubAPIErrorResponse, so rate-limit details are lost (list_releases, security advisories, search_issues and others)

2 participants