{"record":{"id":"359f9ea2e673bcc9","repo":"JuliusBrussee/caveman","slug":"read-usage-export-w","errorCode":null,"errorMessage":"read usage export: %w","messagePattern":"read usage export: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/learn_reconcile.go","lineNumber":137,"sourceCode":"\tif !ok || index >= len(record) {\n\t\treturn 0\n\t}\n\traw := strings.TrimSpace(strings.ReplaceAll(record[index], \",\", \"\"))\n\tif raw == \"\" {\n\t\treturn 0\n\t}\n\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}","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/81536f57b3303b7de7f5bc5b564cc344f9112d68/proxy/internal/store/learn_reconcile.go#L119-L155","documentation":"parseUsageExport wraps errors from opening the provider usage CSV file. If the export path is unreadable (missing file, permissions), the reconcile cannot compare billed tokens and fails with this wrapped cause.","triggerScenarios":"Thrown at proxy/internal/store/learn_reconcile.go:137 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the usage-export path passed to caveman learn reconcile is correct","Check the file exists and is readable by the current user","Re-export the usage CSV from the provider if it was deleted"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"81536f57b3303b7de7f5bc5b564cc344f9112d68","analyzedAt":"2026-08-27T02:25:50.681Z","contentChangedAt":"2026-08-27T02:25:50.681Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}