From 5df7fff2486386eb5b8499d8dc912e60ce6ed355 Mon Sep 17 00:00:00 2001 From: Adam Holt Date: Wed, 10 Dec 2025 13:34:14 +0000 Subject: [PATCH 1/2] Add API Error annotations to GitHub issue errors --- pkg/errors/error.go | 8 ++++++++ pkg/github/issues.go | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/errors/error.go b/pkg/errors/error.go index be2cf58f9..b3f578569 100644 --- a/pkg/errors/error.go +++ b/pkg/errors/error.go @@ -91,6 +91,14 @@ func NewGitHubAPIErrorToCtx(ctx context.Context, message string, resp *github.Re return ctx, nil } +func NewGitHubGraphQLErrorToCtx(ctx context.Context, message string, err error) (context.Context, error) { + graphQLErr := newGitHubGraphQLError(message, err) + if ctx != nil { + _, _ = addGitHubGraphQLErrorToContext(ctx, graphQLErr) // Explicitly ignore error for graceful handling + } + return ctx, nil +} + func addGitHubAPIErrorToContext(ctx context.Context, err *GitHubAPIError) (context.Context, error) { if val, ok := ctx.Value(GitHubErrorKey{}).(*GitHubCtxErrors); ok { val.api = append(val.api, err) // append the error to the existing slice in the context diff --git a/pkg/github/issues.go b/pkg/github/issues.go index 46111a4d6..c2d004829 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -1161,7 +1161,11 @@ func CreateIssue(ctx context.Context, client *github.Client, owner string, repo issue, resp, err := client.Issues.Create(ctx, owner, repo, issueRequest) if err != nil { - return utils.NewToolResultErrorFromErr("failed to create issue", err), nil + return ghErrors.NewGitHubAPIErrorResponse(ctx, + "failed to create issue", + resp, + err, + ), nil } defer func() { _ = resp.Body.Close() }() @@ -1495,7 +1499,11 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun issueQuery := getIssueQueryType(hasLabels, hasSince) if err := client.Query(ctx, issueQuery, vars); err != nil { - return utils.NewToolResultError(err.Error()), nil, nil + return ghErrors.NewGitHubGraphQLErrorResponse( + ctx, + "failed to list issues", + err, + ), nil, nil } // Extract and convert all issue nodes using the common interface @@ -1653,6 +1661,7 @@ func AssignCopilotToIssue(getGQLClient GetGQLClientFn, t translations.Translatio var query suggestedActorsQuery err := client.Query(ctx, &query, variables) if err != nil { + _, _ = ghErrors.NewGitHubGraphQLErrorToCtx(ctx, "failed to get suggested actors", err) return nil, nil, err } @@ -1699,7 +1708,7 @@ func AssignCopilotToIssue(getGQLClient GetGQLClientFn, t translations.Translatio } if err := client.Query(ctx, &getIssueQuery, variables); err != nil { - return utils.NewToolResultError(fmt.Sprintf("failed to get issue ID: %v", err)), nil, nil + return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to get issue ID", err), nil, nil } // Finally, do the assignment. Just for reference, assigning copilot to an issue that it is already From 0dcbe3e4105f89e517a6701de7849293f7597248 Mon Sep 17 00:00:00 2001 From: Adam Holt Date: Wed, 10 Dec 2025 14:07:17 +0000 Subject: [PATCH 2/2] Return an error back. --- pkg/github/issues.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/github/issues.go b/pkg/github/issues.go index c2d004829..cd539faaf 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -1661,8 +1661,7 @@ func AssignCopilotToIssue(getGQLClient GetGQLClientFn, t translations.Translatio var query suggestedActorsQuery err := client.Query(ctx, &query, variables) if err != nil { - _, _ = ghErrors.NewGitHubGraphQLErrorToCtx(ctx, "failed to get suggested actors", err) - return nil, nil, err + return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to get suggested actors", err), nil, nil } // Iterate all the returned nodes looking for the copilot bot, which is supposed to have the