{"record":{"id":"54e6f1217d082f20","repo":"github/github-mcp-server","slug":"failed-to-close-base64-encoder-w","errorCode":null,"errorMessage":"failed to close base64 encoder: %w","messagePattern":"failed to close base64 encoder: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"pkg/github/repository_resource.go","lineNumber":235,"sourceCode":"\t\t\tcase strings.HasPrefix(mimeType, \"text\"), strings.HasPrefix(mimeType, \"application\"):\n\t\t\t\treturn &mcp.ReadResourceResult{\n\t\t\t\t\tContents: []*mcp.ResourceContents{\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tURI:      request.Params.URI,\n\t\t\t\t\t\t\tMIMEType: mimeType,\n\t\t\t\t\t\t\tText:     string(content),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}, nil\n\t\t\tdefault:\n\t\t\t\tvar buf bytes.Buffer\n\t\t\t\tbase64Encoder := base64.NewEncoder(base64.StdEncoding, &buf)\n\t\t\t\t_, err := base64Encoder.Write(content)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"failed to base64 encode content: %w\", err)\n\t\t\t\t}\n\t\t\t\tif err := base64Encoder.Close(); err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"failed to close base64 encoder: %w\", err)\n\t\t\t\t}\n\n\t\t\t\treturn &mcp.ReadResourceResult{\n\t\t\t\t\tContents: []*mcp.ResourceContents{\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tURI:      request.Params.URI,\n\t\t\t\t\t\t\tMIMEType: mimeType,\n\t\t\t\t\t\t\tBlob:     buf.Bytes(),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}, nil\n\t\t\t}\n\t\tcase resp.StatusCode != http.StatusNotFound:\n\t\t\t// If we got a response but it is not 200 OK, we return an error\n\t\t\tbody, err := io.ReadAll(resp.Body)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to read response body: %w\", err)\n\t\t\t}","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/repository_resource.go#L217-L253","documentation":"Returned when base64Encoder.Close() fails after encoding binary content for a repo:// resource. Close flushes the final base64 block into the same bytes.Buffer; since bytes.Buffer writes never fail, this error is effectively unreachable defensive code. Seeing it would indicate memory exhaustion or a corrupted runtime rather than any GitHub condition.","triggerScenarios":"Same blob path as the Write error (non-text MIME type); Close on an encoder over a bytes.Buffer has no failure mode in practice. No realistic API call produces this error.","commonSituations":"Not observed in practice; encountered only during code review of the encoding branch.","solutions":["No runtime action needed - the path is unreachable with a bytes.Buffer sink","Replace the encoder with base64.StdEncoding.EncodeToString(content) to delete both error branches and make the invariant explicit"],"exampleFix":"// before\nif err := base64Encoder.Close(); err != nil {\n    return nil, fmt.Errorf(\"failed to close base64 encoder: %w\", err)\n}\n// after - no encoder, no close\nblob := base64.StdEncoding.EncodeToString(content)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to close base64 encoder\") {\n    // Unreachable with a bytes.Buffer sink: report upstream\n    log.Error(\"unexpected base64 close failure\", \"err\", err)\n}","preventionTips":["No prevention needed - the path cannot execute with a bytes.Buffer writer","Simplify to base64.StdEncoding.EncodeToString in local forks to delete the branch"],"tags":["go","base64","resource","dead-code"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}