{"record":{"id":"2f5def527a6d676a","repo":"JuliusBrussee/caveman","slug":"usage-export-row-w","errorCode":null,"errorMessage":"usage export row: %w","messagePattern":"usage export row: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/learn_reconcile.go","lineNumber":157,"sourceCode":"\tdefer file.Close()\n\treader := csv.NewReader(file)\n\treader.FieldsPerRecord = -1\n\theader, err := reader.Read()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"usage export has no header row: %w\", err)\n\t}\n\tcolumns, err := mapReconcileHeader(header)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tbilled := map[string]int64{}\n\tfor {\n\t\trecord, err := reader.Read()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"usage export row: %w\", err)\n\t\t}\n\t\tmodelIndex := columns[\"model\"]\n\t\tif modelIndex >= len(record) {\n\t\t\tcontinue\n\t\t}\n\t\tmodel := strings.TrimSpace(record[modelIndex])\n\t\tif model == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\ttotal := reconcileCell(record, columns, \"input\") +\n\t\t\treconcileCell(record, columns, \"output\") +\n\t\t\treconcileCell(record, columns, \"cache_read\") +\n\t\t\treconcileCell(record, columns, \"cache_write\")\n\t\tif total <= 0 {\n\t\t\tcontinue\n\t\t}\n\t\tbilled[model] += total\n\t}","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/store/learn_reconcile.go#L139-L175","documentation":"While iterating data rows, csv.Reader.Read() returned a non-EOF error; parseUsageExport wraps it as \"usage export row\". Reader.FieldsPerRecord is set to -1 so ragged rows are allowed; this error covers malformed CSV structure (unbalanced quotes, bare quotes) and mid-file I/O errors.","triggerScenarios":"A data row in the usage CSV has malformed quoting (e.g. an unclosed \", a quote not doubled inside a quoted field), or the underlying file read fails partway through.","commonSituations":"Hand-edited CSV rows; exports containing quoted model names that were mangled by another tool; copy-pasting rows into the CSV with broken quoting.","solutions":["Open the file, locate the malformed row at the error's line/column, and fix quoting (double embedded quotes)","Re-export the CSV from the provider instead of hand-editing","Validate the CSV with a parser/linter (e.g. python -m csv) before running reconcile"],"exampleFix":"// before\nmodel,input_tokens\n\"gpt-4o,1000   // unclosed quote\n// after\nmodel,input_tokens\n\"gpt-4o\",1000","handlingStrategy":"try-catch","validationCode":"// pre-validate with a strict CSV reader\nr := csv.NewReader(f); r.FieldsPerRecord = -1; if _, err := r.ReadAll(); err != nil { return fmt.Errorf(\"malformed usage CSV: %w\", err) }","typeGuard":null,"tryCatchPattern":"if _, err := store.BuildLearnReconcile(ctx, opts); err != nil { if strings.Contains(err.Error(), \"usage export row\") { log.Error(\"malformed CSV row; fix quoting or re-export: \", err) } }","preventionTips":["Never hand-edit provider CSVs; re-export instead","Run csv.Reader.ReadAll() as a pre-flight lint in tooling","Beware tools that reformat quotes when editing CSVs"],"tags":["csv","parse","malformed"],"backgroundTag":"csv-parse-error","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}