{"record":{"id":"3a94382108443591","repo":"github/github-mcp-server","slug":"failed-to-flush-csv-w","errorCode":null,"errorMessage":"failed to flush CSV: %w","messagePattern":"failed to flush CSV: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"pkg/github/csv_output.go","lineNumber":150,"sourceCode":"\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),\n\t\t\t\trows:     csvRowsFromArray(rows),\n\t\t\t}\n\t\t}\n\t\treturn csvOutputDocument{rows: []map[string]string{newFlattenedCSVRow(v)}}\n\tdefault:\n\t\treturn csvOutputDocument{rows: []map[string]string{scalarCSVRow(v)}}","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/csv_output.go#L132-L168","documentation":"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.","triggerScenarios":"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.","commonSituations":"Forks streaming CSV to sockets/files; official in-memory conversion cannot produce this error.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"writer.Flush()\nif err := writer.Error(); err != nil {\n\t// buffered content is complete in memory: log, and if the destination is fallible, return partial output with a truncation flag\n\treturn \"\", fmt.Errorf(\"failed to flush CSV: %w\", err)\n}","preventionTips":["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"],"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"}