github/github-mcp-server · info
failed to write CSV row: %w
Error message
failed to write CSV row: %w
What it means
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.
Source
Thrown at pkg/github/csv_output.go:144
}
headers := csvHeaders(doc.rows)
if len(headers) == 0 {
return buf.String(), nil
}
writer := csv.NewWriter(&buf)
if err := writer.Write(headers); err != nil {
return "", fmt.Errorf("failed to write CSV header: %w", err)
}
for _, row := range doc.rows {
record := make([]string, len(headers))
for i, header := range headers {
record[i] = row[header]
}
if err := writer.Write(record); err != nil {
return "", fmt.Errorf("failed to write CSV row: %w", err)
}
}
writer.Flush()
if err := writer.Error(); err != nil {
return "", fmt.Errorf("failed to flush CSV: %w", err)
}
return buf.String(), nil
}
func csvDocument(value any) csvOutputDocument {
switch v := value.(type) {
case []any:
return csvOutputDocument{rows: csvRowsFromArray(v)}
case map[string]any:
if rows, metadata, ok := primaryRowsFromMap(v); ok {
return csvOutputDocument{
metadata: newFlattenedCSVRow(metadata),View on GitHub (pinned to 0ea1f775a7)
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
Defensive patterns
Strategy: try-catch
Try / catch
if err := writer.Write(record); err != nil {
// in-memory buffer: invariant failure — abort conversion and report payload size
return "", fmt.Errorf("failed to write CSV row: %w", err)
} Prevention
- Shrink result sets (per_page, field filters) before CSV conversion
- If streaming to fallible writers in forks, check errors per row and stop early
When it happens
Trigger: 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.
Common situations: Huge paginated outputs converted to CSV in constrained containers; effectively unreachable otherwise.
Related errors
- failed to write CSV header: %w
- failed to flush CSV: %w
- failed to unmarshal JSON text: %w
- failed to marshal discussions: %w
- failed to marshal discussion: %w
AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15).
Data as JSON: /api/errors/da04db14b3e5f12a.
Report an issue: GitHub.