{"record":{"id":"4ea32cf139e7ea2d","repo":"Tencent/WeKnora","slug":"csv-conversion-failed-w","errorCode":null,"errorMessage":"csv conversion failed: %w","messagePattern":"csv conversion failed: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/docparser/builtin_converter.go","lineNumber":64,"sourceCode":"// bypassing the Python docreader service.\ntype SimpleFormatReader struct{}\n\n// Read reads simple format files and returns markdown.\nfunc (b *SimpleFormatReader) Read(_ context.Context, req *types.ReadRequest) (*types.ReadResult, error) {\n\tft := strings.ToLower(strings.TrimPrefix(req.FileType, \".\"))\n\tif ft == \"\" {\n\t\tft = strings.TrimPrefix(strings.ToLower(filepath.Ext(req.FileName)), \".\")\n\t}\n\n\tswitch {\n\tcase ft == \"md\" || ft == \"markdown\":\n\t\treturn &types.ReadResult{MarkdownContent: string(req.FileContent)}, nil\n\tcase ft == \"txt\" || ft == \"text\":\n\t\treturn &types.ReadResult{MarkdownContent: string(req.FileContent)}, nil\n\tcase ft == \"csv\":\n\t\tmd, err := csvToMarkdown(req.FileContent)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"csv conversion failed: %w\", err)\n\t\t}\n\t\treturn &types.ReadResult{MarkdownContent: md}, nil\n\tcase ft == \"json\":\n\t\tmd, err := jsonToMarkdown(req.FileContent)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"json conversion failed: %w\", err)\n\t\t}\n\t\treturn &types.ReadResult{MarkdownContent: md}, nil\n\tcase imageFormats[ft]:\n\t\treturn imageToResult(req.FileName, req.FileContent), nil\n\tcase audioFormats[ft]:\n\t\treturn audioToResult(req.FileName, req.FileContent), nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported simple format: %s\", ft)\n\t}\n}\n\n// imageToResult wraps a standalone image as a markdown image reference with","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/docparser/builtin_converter.go#L46-L82","documentation":"The built-in document converter converts CSV files to Markdown tables via csvToMarkdown. This error wraps any failure in that conversion — most commonly malformed CSV (ragged rows, bad quoting, wrong delimiter) that the Go encoding/csv parser rejects.","triggerScenarios":"Calling Read with a request whose detected file type is \"csv\" and where csvToMarkdown fails: unterminated quotes, invalid rune in quote, or inconsistent field counts per row.","commonSituations":"Users upload Excel-exported CSVs with semicolon or tab delimiters assumed to be comma; embedded unescaped quotes/newlines; files with a BOM or mixed encodings (GBK/latin-1) breaking the parser; files renamed .csv but actually TSV.","solutions":["Open the file and fix the malformed CSV row/column the underlying error points to.","Pre-convert the file to well-formed UTF-8 comma-separated CSV (or resave from Excel as 'CSV UTF-8').","Convert the delimiter to a comma (or extend csvToMarkdown to sniff delimiters).","If the file is genuinely tab-separated, rename to .tsv and route through a TSV handler."],"exampleFix":"// before\n# data.csv with semicolons\name;age\nBob;3\n// after\n# re-export as comma-separated UTF-8\nname,age\nBob,3","handlingStrategy":"validation","validationCode":"r := csv.NewReader(bytes.NewReader(req.FileContent))\nr.FieldsPerRecord = -1\nif _, err := r.ReadAll(); err != nil {\n    return fmt.Errorf(\"not valid CSV: %w\", err)\n}","typeGuard":"func looksLikeCSV(data []byte) bool {\n    r := csv.NewReader(bytes.NewReader(data)); r.FieldsPerRecord = -1\n    rows, err := r.ReadAll(); return err == nil && len(rows) > 0\n}","tryCatchPattern":"res, err := reader.Read(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"csv conversion failed\") {\n    var csvErr *csv.ParseError\n    if errors.As(err, &csvErr) { log.Printf(\"bad CSV at line %d\", csvErr.Line) }\n}","preventionTips":["Export CSVs as UTF-8 comma-separated from Excel/Sheets.","Avoid unescaped quotes and mixed delimiters in uploaded files.","Strip BOMs and convert non-UTF-8 encodings before upload.","Pre-validate CSV parseability client-side before calling Read."],"tags":["csv","docparser","conversion","format"],"backgroundTag":"csv-parse-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}