{"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/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/store/learn_reconcile.go#L119-L155","documentation":"Wrapped error from parseUsageExport: opening/reading the provider usage-export CSV failed at the OS level (missing file, permission, unreadable path). The underlying os.Open error is included via %w so the cause stays inspectable.","triggerScenarios":"Calling BuildLearnReconcile with a usage-export path that doesn't exist, has wrong permissions, or is in a missing directory.","commonSituations":"Typo'd --usage-export path; file not downloaded from the provider dashboard yet; running in a container where the file wasn't mounted.","solutions":["Verify the path exists and is readable (ls -l) before running reconcile","Download/re-export the provider usage CSV to the expected location","Fix the mount or copy the file into the container/working directory"],"exampleFix":"// before\ncaveman learn reconcile --usage-export ./usag.csv\n// after\ncaveman learn reconcile --usage-export ./usage.csv","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(path); err != nil || info.IsDir() { return fmt.Errorf(\"usage export not a readable file: %s\", path) }","typeGuard":null,"tryCatchPattern":"if _, err := store.BuildLearnReconcile(ctx, opts); err != nil { var perr *fs.PathError; if errors.As(err, &perr) { log.Errorf(\"cannot open usage export %s: %v\", perr.Path, perr.Err) } }","preventionTips":["Stat the file before invoking reconcile","Use shell/tab completion for paths to avoid typos","Ensure the file is mounted/copied into containers before running"],"tags":["file","io","csv"],"backgroundTag":"file-open-failed","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"}