Skip to content

Commit 3f87488

Browse files
Fix response body handling and remove unreachable code
Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
1 parent b8f0b13 commit 3f87488

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pkg/github/issues.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,6 @@ func AddSubIssue(ctx context.Context, client *github.Client, owner string, repo
824824

825825
// Success case
826826
if err == nil && resp.StatusCode == http.StatusCreated {
827-
defer func() { _ = resp.Body.Close() }()
828827
r, err := json.Marshal(subIssue)
829828
if err != nil {
830829
return nil, fmt.Errorf("failed to marshal response: %w", err)
@@ -860,15 +859,16 @@ func AddSubIssue(ctx context.Context, client *github.Client, owner string, repo
860859

861860
// Handle non-201 status codes after retries exhausted
862861
if lastResp != nil && lastResp.StatusCode != http.StatusCreated {
863-
defer func() { _ = lastResp.Body.Close() }()
864862
body, err := io.ReadAll(lastResp.Body)
863+
defer func() { _ = lastResp.Body.Close() }()
865864
if err != nil {
866865
return nil, fmt.Errorf("failed to read response body: %w", err)
867866
}
868867
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to add sub-issue", lastResp, body), nil
869868
}
870869

871-
return nil, fmt.Errorf("failed to add sub-issue after %d retries", maxRetries)
870+
// This should not be reached in normal operation
871+
return nil, fmt.Errorf("unexpected error: failed to add sub-issue")
872872
}
873873

874874
func RemoveSubIssue(ctx context.Context, client *github.Client, owner string, repo string, issueNumber int, subIssueID int) (*mcp.CallToolResult, error) {

0 commit comments

Comments
 (0)