{"record":{"id":"e4218d647e478dad","repo":"github/github-mcp-server","slug":"failed-to-base64-encode-content-w","errorCode":null,"errorMessage":"failed to base64 encode content: %w","messagePattern":"failed to base64 encode content: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"pkg/github/repository_resource.go","lineNumber":232,"sourceCode":"\t\t\t}\n\n\t\t\tswitch {\n\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)","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/repository_resource.go#L214-L250","documentation":"Returned when base64Encoder.Write(content) fails while encoding a non-text (blob) file for a repo:// resource. The encoder writes into a bytes.Buffer, whose Write method can never return an error (it grows on demand), so this branch is effectively unreachable defensive code that exists only because the encoder API returns an error. If you ever see it, treat it as a bug report, not an environmental problem.","triggerScenarios":"Only reachable when the MIME type of a fetched file is neither text/* nor application/*, so the blob path runs - and even then bytes.Buffer.Write cannot fail in practice. No realistic API call produces this error.","commonSituations":"Not observed in practice; developers encounter it while reading the code and wondering about the error path.","solutions":["No runtime action needed - the path is unreachable with a bytes.Buffer sink","Simplify the handler by replacing the streaming encoder with base64.StdEncoding.EncodeToString(content), which removes both this and the Close error branch"],"exampleFix":"// before\nvar buf bytes.Buffer\nenc := base64.NewEncoder(base64.StdEncoding, &buf)\nif _, err := enc.Write(content); err != nil {\n    return nil, fmt.Errorf(\"failed to base64 encode content: %w\", err)\n}\n// after\nblob := base64.StdEncoding.EncodeToString(content)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to base64 encode content\") {\n    // Unreachable with a bytes.Buffer sink: treat as a bug, not an environment problem\n    log.Error(\"unexpected base64 encode failure\", \"err\", err)\n}","preventionTips":["Treat this error as an upstream bug if it ever fires - file an issue rather than adding handling","When patching this file, replace the streaming encoder with base64.StdEncoding.EncodeToString to remove 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"}