{"record":{"id":"4467cbc4a542316f","repo":"JuliusBrussee/caveman","slug":"usage-export-has-no-header-row-w","errorCode":null,"errorMessage":"usage export has no header row: %w","messagePattern":"usage export has no header row: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/learn_reconcile.go","lineNumber":144,"sourceCode":"\tvalue, err := strconv.ParseFloat(raw, 64)\n\tif err != nil || value < 0 {\n\t\treturn 0\n\t}\n\treturn int64(value)\n}\n\n// parseUsageExport reads a provider usage CSV into billed tokens per model.\nfunc parseUsageExport(path string) (map[string]int64, error) {\n\tfile, err := os.Open(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read usage export: %w\", err)\n\t}\n\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}","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/store/learn_reconcile.go#L126-L162","documentation":"After opening the CSV, parseUsageExport reads the first row as the header. If csv.Reader.Read() fails (empty file, or a non-CSV/binary file with a read error) it wraps the cause as \"usage export has no header row\". This keeps schema detection from running on nothing.","triggerScenarios":"The usage-export file is empty (zero bytes), or reading the first line errors (binary content, decode error, I/O failure on first read).","commonSituations":"Provider export failed and produced a 0-byte file; pointing reconcile at an HTML error page saved instead of the CSV; truncated download.","solutions":["Check the file is non-empty and is a real CSV (head -1 usage.csv)","Re-download/re-export the usage file from the provider","Fix any truncated or partial download before running reconcile"],"exampleFix":"// before\n$ wc -c usage.csv\n0\n// after\n$ head -1 usage.csv\nmodel,input_tokens,output_tokens\n","handlingStrategy":"validation","validationCode":"fi, _ := os.Stat(path); if fi.Size() == 0 { return fmt.Errorf(\"usage export is empty: %s\", path) }","typeGuard":null,"tryCatchPattern":"if _, err := store.BuildLearnReconcile(ctx, opts); err != nil { if strings.Contains(err.Error(), \"no header row\") { log.Error(\"usage export empty or not CSV; re-download\") } }","preventionTips":["Check file size > 0 after downloading the export","Verify the file is CSV (starts with a header line), not HTML/JSON","Detect truncated downloads via provider-provided checksums"],"tags":["csv","file","empty-file"],"backgroundTag":"invalid-csv-header","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"}