{"record":{"id":"da04db14b3e5f12a","repo":"github/github-mcp-server","slug":"failed-to-write-csv-row-w","errorCode":null,"errorMessage":"failed to write CSV row: %w","messagePattern":"failed to write CSV row: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"pkg/github/csv_output.go","lineNumber":144,"sourceCode":"\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}\n\nfunc csvDocument(value any) csvOutputDocument {\n\tswitch v := value.(type) {\n\tcase []any:\n\t\treturn csvOutputDocument{rows: csvRowsFromArray(v)}\n\tcase map[string]any:\n\t\tif rows, metadata, ok := primaryRowsFromMap(v); ok {\n\t\t\treturn csvOutputDocument{\n\t\t\t\tmetadata: newFlattenedCSVRow(metadata),","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/csv_output.go#L126-L162","documentation":"csv.Writer.Write failed while emitting a data row into the in-memory bytes.Buffer. Because bytes.Buffer writes cannot error and csv field values are plain strings, this is defensive code with no realistic trigger; a failure would indicate resource exhaustion or a modified build rather than problematic row data.","triggerScenarios":"CSV conversion of a JSON rows array where the buffer write fails — only plausible under extreme memory pressure or in altered code that swaps the buffer for a fallible writer.","commonSituations":"Huge paginated outputs converted to CSV in constrained containers; effectively unreachable otherwise.","solutions":["Reduce result size via pagination or field filters before requesting CSV output","Increase memory limits if large CSV exports are expected","Report as an invariant violation if it recurs on modest payloads"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := writer.Write(record); err != nil {\n\t// in-memory buffer: invariant failure — abort conversion and report payload size\n\treturn \"\", fmt.Errorf(\"failed to write CSV row: %w\", err)\n}","preventionTips":["Shrink result sets (per_page, field filters) before CSV conversion","If streaming to fallible writers in forks, check errors per row and stop early"],"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"}