charmbracelet/crush · error
get usage by day of week: %w
Error message
get usage by day of week: %w
What it means
gatherStats fetches day-of-week usage via queries.GetUsageByDayOfWeek and wraps any SQL failure with this message. It indicates the aggregate query could not run against the sessions database — access, locking, or schema issues rather than a stats-logic problem.
Source
Thrown at internal/cmd/stats.go:606
})
}
// Usage by hour.
hourlyUsage, err := queries.GetUsageByHour(ctx)
if err != nil {
return nil, fmt.Errorf("get usage by hour: %w", err)
}
for _, h := range hourlyUsage {
stats.UsageByHour = append(stats.UsageByHour, HourlyUsage{
Hour: int(h.Hour),
SessionCount: h.SessionCount,
})
}
// Usage by day of week.
dowUsage, err := queries.GetUsageByDayOfWeek(ctx)
if err != nil {
return nil, fmt.Errorf("get usage by day of week: %w", err)
}
for _, d := range dowUsage {
stats.UsageByDayOfWeek = append(stats.UsageByDayOfWeek, DayOfWeekUsage{
DayOfWeek: int(d.DayOfWeek),
DayName: dayNames[int(d.DayOfWeek)],
SessionCount: d.SessionCount,
PromptTokens: nullFloat64ToInt64(d.PromptTokens),
CompletionTokens: nullFloat64ToInt64(d.CompletionTokens),
})
}
// Recent activity (last 30 days).
recent, err := queries.GetRecentActivity(ctx)
if err != nil {
return nil, fmt.Errorf("get recent activity: %w", err)
}
for _, r := range recent {
stats.RecentActivity = append(stats.RecentActivity, DailyActivity{View on GitHub (pinned to 7944b8e522)
Solutions
- Stop other crush processes and retry
- Fix ownership/permissions: `chown -R $USER .crush`
- Run `PRAGMA integrity_check`; restore or delete a corrupt DB
- Ensure the crush binary and DB schema versions match
Example fix
// before -rw------- 1 root root crush.db # run via sudo once, now unreadable // after sudo chown $USER .crush/crush.db && crush stats
Defensive patterns
Strategy: retry
Validate before calling
db="${CRUSH_DATA_DIR:-.crush}/crush.db"
[ -r "$db" ] && [ -w "$db" ] && sqlite3 "$db" 'PRAGMA integrity_check;' | grep -q ok && echo ok || echo "DB access/integrity problem" Try / catch
if err := gatherStats(ctx, dbPath); err != nil {
if strings.Contains(err.Error(), "get usage by day of week") && errors.Is(err, os.ErrPermission) {
fmt.Fprintln(os.Stderr, "Fix ownership: chown -R $USER .crush")
return nil
}
return err
} Prevention
- Ensure consistent file ownership of the data dir across runs
- Avoid mixing sudo and normal-user invocations
- Retry transient lock errors instead of immediately failing
- Keep network-filesystem usage away from SQLite files
- Check integrity after crashes and upgrades
When it happens
Trigger: GetUsageByDayOfWeek fails: SQLite locked by another writer, unreadable/corrupt DB file, or the query's expected tables/columns missing due to version/schema mismatch.
Common situations: Multiple crush instances; DB on an unreliable mount; partial migration after an upgrade; wrong --data-dir; DB owned by another user after a sudo run.
Related errors
- get total stats: %w
- get usage by day: %w
- get usage by model: %w
- get usage by hour: %w
- get recent activity: %w
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/999c488fd236f3d6.
Report an issue: GitHub.