{"record":{"id":"0ccd6a55b8fa3619","repo":"charmbracelet/crush","slug":"no-data-available-no-sessions-found-in-database","errorCode":null,"errorMessage":"no data available: no sessions found in database","messagePattern":"no data available: no sessions found in database","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/cmd/stats.go","lineNumber":194,"sourceCode":"\t\tdefer conn.Close()\n\n\t\tstats, err := gatherStats(ctx, conn)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to gather stats: %w\", err)\n\t\t}\n\n\t\tprojectStats = []ProjectStats{{ProjectPath: \"\", Stats: stats}}\n\t}\n\n\tif len(projectStats) == 0 {\n\t\treturn fmt.Errorf(\"no data available: no projects found\")\n\t}\n\n\t// Merge stats from all projects.\n\tmergedStats := mergeStats(projectStats)\n\n\tif mergedStats.Total.TotalSessions == 0 {\n\t\treturn fmt.Errorf(\"no data available: no sessions found in database\")\n\t}\n\n\tcurrentUser, err := user.Current()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get current user: %w\", err)\n\t}\n\tusername := currentUser.Username\n\n\tvar projName string\n\tswitch {\n\tcase crawlDir != \"\":\n\t\tprojName = crawlDir\n\tcase useAll:\n\t\tprojName = \"all projects\"\n\tdefault:\n\t\tproject, err := os.Getwd()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to get current directory: %w\", err)","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/stats.go#L176-L212","documentation":"runStats returns this hard-coded error when project databases were found and merged, but mergedStats.Total.TotalSessions == 0 — i.e. the database(s) exist yet contain no sessions. It distinguishes an empty-but-valid database from the no-projects case.","triggerScenarios":"Running `crush stats` (or --all/--crawl-dir) against data dirs where crush.db exists but the sessions table is empty — fresh installs, databases wiped/reset, crawl dirs containing only initialized crush projects with no conversations; also after manually deleting session rows or restoring an empty db.","commonSituations":"New machine or new project where crush was opened but never used; user cleared ~/.local/share/crush/crush.db to fix a problem and then ran stats; crawl-dir matching dotfile/build dirs containing stray empty crush.db files.","solutions":["Use crush to start a session (chat once) so data is recorded, then rerun stats.","Check the sessions table directly: sqlite3 <dataDir>/crush.db 'SELECT COUNT(*) FROM sessions;' to confirm it is empty.","If you expect data, verify you are pointing at the correct data dir (HOME/XDG_DATA_HOME overrides) and correct --crawl-dir/--all targets.","If sessions were deleted intentionally, accept the message or remove the empty db so fresh history accumulates."],"exampleFix":"// before\nXDG_DATA_HOME=/tmp crush stats   # looks at an empty data dir\n// after\ncrush stats                       # uses the real data dir with recorded sessions","handlingStrategy":"validation","validationCode":"n, err := queryCount(conn, \"SELECT COUNT(*) FROM sessions\")\nif err != nil {\n\treturn err\n}\nif n == 0 {\n\treturn fmt.Errorf(\"skipping stats: database has no sessions yet\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use crush to record at least one session before running stats.","Verify you are using the data dir that actually holds your history (check XDG_DATA_HOME/HOME overrides).","Don't delete or reset crush.db if you rely on stats.","When crawling, exclude directories with freshly-initialized empty projects."],"tags":["cli","stats","empty-data","sqlite"],"backgroundTag":"no-data-found","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}