{"record":{"id":"885f3b262abf2ad1","repo":"github/github-mcp-server","slug":"failed-to-write-csv-header-w","errorCode":null,"errorMessage":"failed to write CSV header: %w","messagePattern":"failed to write CSV header: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"pkg/github/csv_output.go","lineNumber":135,"sourceCode":"\tdoc := csvDocument(value)\n\tif len(doc.metadata) == 0 && len(doc.rows) == 0 {\n\t\treturn \"\", nil\n\t}\n\n\tvar buf bytes.Buffer\n\twriteCSVMetadata(&buf, doc.metadata)\n\tif len(doc.rows) == 0 {\n\t\treturn buf.String(), nil\n\t}\n\n\theaders := csvHeaders(doc.rows)\n\tif len(headers) == 0 {\n\t\treturn buf.String(), nil\n\t}\n\n\twriter := csv.NewWriter(&buf)\n\tif err := writer.Write(headers); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to write CSV header: %w\", err)\n\t}\n\n\tfor _, row := range doc.rows {\n\t\trecord := make([]string, len(headers))\n\t\tfor i, header := range headers {\n\t\t\trecord[i] = row[header]\n\t\t}\n\t\tif err := writer.Write(record); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to write CSV row: %w\", err)\n\t\t}\n\t}\n\n\twriter.Flush()\n\tif err := writer.Error(); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to flush CSV: %w\", err)\n\t}\n\treturn buf.String(), nil\n}","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/csv_output.go#L117-L153","documentation":"csv.Writer.Write failed while emitting the header row into a bytes.Buffer. The Go csv writer only returns errors from the underlying writer or on field-count/quoting invariants, and a bytes.Buffer's Write never returns an error, so this branch is effectively unreachable defensive code. Reaching it implies memory exhaustion or buffer corruption rather than a data problem.","triggerScenarios":"Converting a JSON document with rows to CSV when the in-memory buffer write fails — practically only under severe memory pressure (OOM-adjacent) or with a corrupted buffer in modified builds.","commonSituations":"Extremely large CSV conversions on memory-constrained containers; not reproducible under normal conditions.","solutions":["If converting very large result sets, request smaller pages (lower per_page) so the CSV fits comfortably in memory","Check container memory limits and raise them if the output is legitimately huge","Otherwise treat as a defensive invariant and report upstream with the error string"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := writer.Write(headers); err != nil {\n\t// bytes.Buffer writes cannot fail: treat as fatal invariant, log and abort conversion\n\treturn \"\", fmt.Errorf(\"failed to write CSV header: %w\", err)\n}","preventionTips":["Bound CSV output size via pagination/filters to stay within memory limits","Monitor container memory when exporting large result sets to CSV"],"tags":["go","csv","encoding","defensive-code","memory"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}