JuliusBrussee/caveman · error
read usage export
Error message
read usage export: %w
What it means
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.
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
Example fix
// before caveman learn reconcile --usage-export ./usag.csv // after caveman learn reconcile --usage-export ./usage.csv
Defensive patterns
Strategy: validation
Validate before calling
if info, err := os.Stat(path); err != nil || info.IsDir() { return fmt.Errorf("usage export not a readable file: %s", path) } Try / catch
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) } } Prevention
- 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
When it happens
Trigger: Calling BuildLearnReconcile with a usage-export path that doesn't exist, has wrong permissions, or is in a missing directory.
Common situations: Typo'd --usage-export path; file not downloaded from the provider dashboard yet; running in a container where the file wasn't mounted.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
- usage export has no header row
- awscreds: read response
- awscreds: read sts response
- caveman agent: invalid .caveman/provider.json
- kms: read response
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/359f9ea2e673bcc9.
Report an issue: GitHub.
Appendix: source
Thrown at proxy/internal/store/learn_reconcile.go:137
if !ok || index >= len(record) {
return 0
}
raw := strings.TrimSpace(strings.ReplaceAll(record[index], ",", ""))
if raw == "" {
return 0
}
value, err := strconv.ParseFloat(raw, 64)
if err != nil || value < 0 {
return 0
}
return int64(value)
}
// parseUsageExport reads a provider usage CSV into billed tokens per model.
func parseUsageExport(path string) (map[string]int64, error) {
file, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("read usage export: %w", err)
}
defer file.Close()
reader := csv.NewReader(file)
reader.FieldsPerRecord = -1
header, err := reader.Read()
if err != nil {
return nil, fmt.Errorf("usage export has no header row: %w", err)
}
columns, err := mapReconcileHeader(header)
if err != nil {
return nil, err
}
billed := map[string]int64{}
for {
record, err := reader.Read()
if err == io.EOF {
break
}View on GitHub (pinned to 3ee70a1026)