Skip to content

Conversation

@omgitsads
Copy link
Member

Annotate raw client errors in the context, to allow us to filter tool call failures in our metrics based on the error type.

@omgitsads omgitsads requested a review from a team as a code owner December 10, 2025 17:01
Copilot AI review requested due to automatic review settings December 10, 2025 17:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for annotating raw client errors in the context to enable error-type-based filtering in metrics. The implementation follows the existing patterns for GitHub API and GraphQL errors.

Key changes:

  • Introduced GitHubRawAPIError type and associated error handling functions
  • Added raw error tracking to GitHubCtxErrors context structure
  • Updated GetFileContents to use the new raw error annotation instead of generic error handling

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pkg/errors/error.go Adds GitHubRawAPIError type, context tracking, and NewGitHubRawAPIErrorResponse function for annotating raw API errors
pkg/github/repositories.go Updates error handling in GetFileContents to use the new raw API error annotation

Comment on lines +48 to +58
type GitHubRawAPIError struct {
Message string `json:"message"`
Response *http.Response `json:"-"`
Err error `json:"-"`
}

func newGitHubRawAPIError(message string, resp *http.Response, err error) *GitHubRawAPIError {
return &GitHubRawAPIError{
Message: message,
Response: resp,
Err: err,
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The GitHubRawAPIError type is missing an Error() string method for consistency with GitHubAPIError and GitHubGraphQLError. This method should be implemented to satisfy the error interface properly.

Add:

func (e *GitHubRawAPIError) Error() string {
	return fmt.Errorf("%s: %w", e.Message, e.Err).Error()
}

Copilot uses AI. Check for mistakes.
Comment on lines 151 to +157
}

func NewGitHubRawAPIErrorResponse(ctx context.Context, message string, resp *http.Response, err error) *mcp.CallToolResult {
rawAPIErr := newGitHubRawAPIError(message, resp, err)
if ctx != nil {
_, _ = addRawAPIErrorToContext(ctx, rawAPIErr) // Explicitly ignore error for graceful handling
}
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The resp *http.Response parameter is accepted but never used. Unlike NewGitHubAPIErrorResponse which stores the response in the error struct, this function doesn't use it. Either:

  1. Store the response in GitHubRawAPIError (add a Response *http.Response field to the struct), or
  2. Remove the unused parameter if the response doesn't need to be stored for raw API errors

For consistency with GitHubAPIError, option 1 is recommended.

Copilot uses AI. Check for mistakes.
Comment on lines 124 to +131
}

func addRawAPIErrorToContext(ctx context.Context, err *GitHubRawAPIError) (context.Context, error) {
if val, ok := ctx.Value(GitHubErrorKey{}).(*GitHubCtxErrors); ok {
val.raw = append(val.raw, err)
return ctx, nil
}

Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

Missing a public GetGitHubRawAPIErrors function to retrieve raw API errors from the context, for consistency with GetGitHubAPIErrors and GetGitHubGraphQLErrors. This function is needed to access the errors stored by NewGitHubRawAPIErrorResponse for metrics filtering purposes (as mentioned in the PR description).

Add after the existing getter functions:

// GetGitHubRawAPIErrors retrieves the slice of GitHubRawAPIErrors from the context.
func GetGitHubRawAPIErrors(ctx context.Context) ([]*GitHubRawAPIError, error) {
	if val, ok := ctx.Value(GitHubErrorKey{}).(*GitHubCtxErrors); ok {
		return val.raw, nil
	}
	return nil, fmt.Errorf("context does not contain GitHubCtxErrors")
}

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +58
type GitHubRawAPIError struct {
Message string `json:"message"`
Response *http.Response `json:"-"`
Err error `json:"-"`
}

func newGitHubRawAPIError(message string, resp *http.Response, err error) *GitHubRawAPIError {
return &GitHubRawAPIError{
Message: message,
Response: resp,
Err: err,
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The new raw API error functionality lacks test coverage. Based on the testing patterns in error_test.go, tests should be added to cover:

  1. Adding raw API errors to context and retrieving them
  2. Accumulating multiple raw API errors
  3. The Error() method (once implemented)
  4. Integration with the existing error context system

This is important since other similar functionality (GitHubAPIError, GitHubGraphQLError) has comprehensive test coverage.

Copilot uses AI. Check for mistakes.
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.

2 participants