{"record":{"id":"0e3696a45a13097a","repo":"github/github-mcp-server","slug":"failed-to-read-response-body-w-0e3696","errorCode":null,"errorMessage":"failed to read response body: %w","messagePattern":"failed to read response body: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/github/repositories.go","lineNumber":111,"sourceCode":"\n\t\t\tclient, err := deps.GetClient(ctx)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to get GitHub client: %w\", err)\n\t\t\t}\n\t\t\tcommit, resp, err := client.Repositories.GetCommit(ctx, owner, repo, sha, opts)\n\t\t\tif err != nil {\n\t\t\t\treturn ghErrors.NewGitHubAPIErrorResponse(ctx,\n\t\t\t\t\tfmt.Sprintf(\"failed to get commit: %s\", sha),\n\t\t\t\t\tresp,\n\t\t\t\t\terr,\n\t\t\t\t), nil, nil\n\t\t\t}\n\t\t\tdefer func() { _ = resp.Body.Close() }()\n\n\t\t\tif resp.StatusCode != 200 {\n\t\t\t\tbody, err := io.ReadAll(resp.Body)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to read response body: %w\", err)\n\t\t\t\t}\n\t\t\t\treturn ghErrors.NewGitHubAPIStatusErrorResponse(ctx, \"failed to get commit\", resp, body), nil, nil\n\t\t\t}\n\n\t\t\t// Convert to minimal commit\n\t\t\tminimalCommit := convertToMinimalCommit(commit, detail)\n\n\t\t\tr, err := json.Marshal(minimalCommit)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to marshal response: %w\", err)\n\t\t\t}\n\n\t\t\tresult := utils.NewToolResultText(string(r))\n\t\t\t// Commit content is reachable from the repo's history; in public\n\t\t\t// repos anyone can land it via a PR (untrusted), in private repos\n\t\t\t// only collaborators can (trusted). Confidentiality follows repo\n\t\t\t// visibility.\n\t\t\tresult = attachRepoVisibilityIFCLabel(ctx, deps, client, owner, repo, result, ifc.LabelCommitContents)","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/repositories.go#L93-L129","documentation":"In get_commit, client.Repositories.GetCommit returned non-200 and the follow-up io.ReadAll(resp.Body) needed for the structured status error failed. The transport read failure replaces the real GitHub status (usually 404 unknown SHA or 422/451 blocked by DMCA/policy).","triggerScenarios":"GetCommit answers 404 (SHA typo, unreferenced object, fork without the commit), 451 (content blocked), 403 (rate limit), then the error body read breaks via connection reset, HTTP/2 stream error, or context cancellation.","commonSituations":"Clients passing shortened or malformed SHAs; repos affected by DMCA takediffs returning 451 with large bodies; rate-limited CI jobs where truncated error bodies coincide; proxy interruptions on GHES.","solutions":["Retry once — read failures are usually transient connection-reuse races","Verify the SHA exists and is reachable from this repo (it must be referenced by a ref or PR)","Check rate-limit headers on adjacent calls if 403s cluster","Inspect the wrapped error for context.Canceled to rule out client timeouts"],"exampleFix":"// before\nbody, err := io.ReadAll(resp.Body)\nif err != nil {\n\treturn nil, nil, fmt.Errorf(\"failed to read response body: %w\", err)\n}\n\n// after — keep the status code visible when the body is lost\nbody, readErr := io.ReadAll(io.LimitReader(resp.Body, 1<<20))\nif readErr != nil {\n\treturn nil, nil, fmt.Errorf(\"failed to read commit body (status %d, sha %s): %w\", resp.StatusCode, sha, readErr)\n}","handlingStrategy":"retry","validationCode":"func validSHA(sha string) error {\n\tif len(sha) < 7 || len(sha) > 40 {\n\t\treturn fmt.Errorf(\"suspicious SHA length %d\", len(sha))\n\t}\n\tfor _, r := range sha {\n\t\tif !strings.ContainsRune(\"0123456789abcdefABCDEF\", r) {\n\t\t\treturn fmt.Errorf(\"SHA contains non-hex character %q\", r)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"res, err := callGetCommit(ctx, owner, repo, sha, detail)\nif err != nil && isTransientReadErr(err) {\n\tres, err = callGetCommit(ctx, owner, repo, sha, detail)\n}","preventionTips":["Validate SHA shape before calling to eliminate the most common 404","Use full 40-char SHAs when provenance matters","Retry only transport-level failures; 404 SHAs need input correction, not retries"],"tags":["go","github-api","mcp","network","io","commits"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}