github/github-mcp-server · info
failed to flush CSV: %w
Error message
failed to flush CSV: %w
What it means
writer.Error() reported a failure after Flush while finishing the CSV document in jsonTextToCSV. encoding/csv defers underlying-writer errors to this call, but the destination is a bytes.Buffer whose writes never fail, so this branch guards against conditions that cannot occur in the stock implementation (e.g., a fork writing to a network stream). It fires only after all rows were already buffered.
Source
Thrown at pkg/github/csv_output.go:150
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),
rows: csvRowsFromArray(rows),
}
}
return csvOutputDocument{rows: []map[string]string{newFlattenedCSVRow(v)}}
default:
return csvOutputDocument{rows: []map[string]string{scalarCSVRow(v)}}View on GitHub (pinned to 0ea1f775a7)
Solutions
- Treat as an invariant violation in stock builds and report upstream with logs
- In forks writing to fallible destinations, handle the error at the writer level and surface it to the caller
- Keep conversions bounded (pagination) to avoid extreme buffer growth
Defensive patterns
Strategy: try-catch
Try / catch
writer.Flush()
if err := writer.Error(); err != nil {
// buffered content is complete in memory: log, and if the destination is fallible, return partial output with a truncation flag
return "", fmt.Errorf("failed to flush CSV: %w", err)
} Prevention
- Keep CSV destinations as bytes.Buffer in-process; move streaming concerns to explicit writers with error handling
- Cap conversion input sizes so flush-time failures cannot lose large amounts of work
When it happens
Trigger: Completing a CSV conversion where the deferred writer error is non-nil — only possible in modified builds using a fallible destination or under memory corruption.
Common situations: Forks streaming CSV to sockets/files; official in-memory conversion cannot produce this error.
Related errors
- failed to write CSV header: %w
- failed to write CSV row: %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/3a94382108443591.
Report an issue: GitHub.