🌐 AI搜索 & 代理 主页
Skip to content

Commit 5df7fff

Browse files
committed
Add API Error annotations to GitHub issue errors
1 parent 82c4930 commit 5df7fff

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

pkg/errors/error.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ func NewGitHubAPIErrorToCtx(ctx context.Context, message string, resp *github.Re
9191
return ctx, nil
9292
}
9393

94+
func NewGitHubGraphQLErrorToCtx(ctx context.Context, message string, err error) (context.Context, error) {
95+
graphQLErr := newGitHubGraphQLError(message, err)
96+
if ctx != nil {
97+
_, _ = addGitHubGraphQLErrorToContext(ctx, graphQLErr) // Explicitly ignore error for graceful handling
98+
}
99+
return ctx, nil
100+
}
101+
94102
func addGitHubAPIErrorToContext(ctx context.Context, err *GitHubAPIError) (context.Context, error) {
95103
if val, ok := ctx.Value(GitHubErrorKey{}).(*GitHubCtxErrors); ok {
96104
val.api = append(val.api, err) // append the error to the existing slice in the context

pkg/github/issues.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,11 @@ func CreateIssue(ctx context.Context, client *github.Client, owner string, repo
11611161

11621162
issue, resp, err := client.Issues.Create(ctx, owner, repo, issueRequest)
11631163
if err != nil {
1164-
return utils.NewToolResultErrorFromErr("failed to create issue", err), nil
1164+
return ghErrors.NewGitHubAPIErrorResponse(ctx,
1165+
"failed to create issue",
1166+
resp,
1167+
err,
1168+
), nil
11651169
}
11661170
defer func() { _ = resp.Body.Close() }()
11671171

@@ -1495,7 +1499,11 @@ func ListIssues(getGQLClient GetGQLClientFn, t translations.TranslationHelperFun
14951499

14961500
issueQuery := getIssueQueryType(hasLabels, hasSince)
14971501
if err := client.Query(ctx, issueQuery, vars); err != nil {
1498-
return utils.NewToolResultError(err.Error()), nil, nil
1502+
return ghErrors.NewGitHubGraphQLErrorResponse(
1503+
ctx,
1504+
"failed to list issues",
1505+
err,
1506+
), nil, nil
14991507
}
15001508

15011509
// Extract and convert all issue nodes using the common interface
@@ -1653,6 +1661,7 @@ func AssignCopilotToIssue(getGQLClient GetGQLClientFn, t translations.Translatio
16531661
var query suggestedActorsQuery
16541662
err := client.Query(ctx, &query, variables)
16551663
if err != nil {
1664+
_, _ = ghErrors.NewGitHubGraphQLErrorToCtx(ctx, "failed to get suggested actors", err)
16561665
return nil, nil, err
16571666
}
16581667

@@ -1699,7 +1708,7 @@ func AssignCopilotToIssue(getGQLClient GetGQLClientFn, t translations.Translatio
16991708
}
17001709

17011710
if err := client.Query(ctx, &getIssueQuery, variables); err != nil {
1702-
return utils.NewToolResultError(fmt.Sprintf("failed to get issue ID: %v", err)), nil, nil
1711+
return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to get issue ID", err), nil, nil
17031712
}
17041713

17051714
// Finally, do the assignment. Just for reference, assigning copilot to an issue that it is already

0 commit comments

Comments
 (0)