Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() }()

Expand Down Expand Up @@ -1506,7 +1510,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
Expand Down Expand Up @@ -1664,7 +1672,7 @@ func AssignCopilotToIssue(getGQLClient GetGQLClientFn, t translations.Translatio
var query suggestedActorsQuery
err := client.Query(ctx, &query, variables)
if err != nil {
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
Expand Down Expand Up @@ -1710,7 +1718,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
Expand Down