Skip to content

Commit 195b0e5

Browse files
Merge branch 'main' into add-logging-stack
2 parents bcd058a + 762845a commit 195b0e5

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

pkg/errors/error.go

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

123+
func NewGitHubGraphQLErrorToCtx(ctx context.Context, message string, err error) (context.Context, error) {
124+
graphQLErr := newGitHubGraphQLError(message, err)
125+
if ctx != nil {
126+
_, _ = addGitHubGraphQLErrorToContext(ctx, graphQLErr) // Explicitly ignore error for graceful handling
127+
}
128+
return ctx, nil
129+
}
130+
123131
func addGitHubAPIErrorToContext(ctx context.Context, err *GitHubAPIError) (context.Context, error) {
124132
if val, ok := ctx.Value(GitHubErrorKey{}).(*GitHubCtxErrors); ok {
125133
val.api = append(val.api, err) // append the error to the existing slice in the context

pkg/github/issues.go

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

11761176
issue, resp, err := client.Issues.Create(ctx, owner, repo, issueRequest)
11771177
if err != nil {
1178-
return utils.NewToolResultErrorFromErr("failed to create issue", err), nil
1178+
return ghErrors.NewGitHubAPIErrorResponse(ctx,
1179+
"failed to create issue",
1180+
resp,
1181+
err,
1182+
), nil
11791183
}
11801184
defer func() { _ = resp.Body.Close() }()
11811185

@@ -1522,7 +1526,11 @@ func ListIssues(t translations.TranslationHelperFunc) inventory.ServerTool {
15221526

15231527
issueQuery := getIssueQueryType(hasLabels, hasSince)
15241528
if err := client.Query(ctx, issueQuery, vars); err != nil {
1525-
return utils.NewToolResultError(err.Error()), nil, nil
1529+
return ghErrors.NewGitHubGraphQLErrorResponse(
1530+
ctx,
1531+
"failed to list issues",
1532+
err,
1533+
), nil, nil
15261534
}
15271535

15281536
// Extract and convert all issue nodes using the common interface
@@ -1683,7 +1691,7 @@ func AssignCopilotToIssue(t translations.TranslationHelperFunc) inventory.Server
16831691
var query suggestedActorsQuery
16841692
err := client.Query(ctx, &query, variables)
16851693
if err != nil {
1686-
return nil, nil, err
1694+
return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to get suggested actors", err), nil, nil
16871695
}
16881696

16891697
// Iterate all the returned nodes looking for the copilot bot, which is supposed to have the
@@ -1729,7 +1737,7 @@ func AssignCopilotToIssue(t translations.TranslationHelperFunc) inventory.Server
17291737
}
17301738

17311739
if err := client.Query(ctx, &getIssueQuery, variables); err != nil {
1732-
return utils.NewToolResultError(fmt.Sprintf("failed to get issue ID: %v", err)), nil, nil
1740+
return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to get issue ID", err), nil, nil
17331741
}
17341742

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

0 commit comments

Comments
 (0)