{"record":{"id":"2ba4c26c8d54aced","repo":"charmbracelet/crush","slug":"no-data-available-no-projects-found","errorCode":null,"errorMessage":"no data available: no projects found","messagePattern":"no data available: no projects found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/cmd/stats.go","lineNumber":187,"sourceCode":"\n\t\tevent.StatsViewed()\n\n\t\tconn, err := db.Connect(ctx, dataDir)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to connect to database: %w\", err)\n\t\t}\n\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 != \"\":","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/stats.go#L169-L205","documentation":"runStats returns this hard-coded error when, after resolving projects (single dir, --crawl-dir, or --all), the projectStats slice is empty — i.e. no project databases were found at all. It is crush's own guard so the command reports a clear message instead of rendering empty statistics.","triggerScenarios":"Running `crush stats --crawl-dir <dir>` over a directory containing no crush projects (no crush.db files anywhere below it); running `crush stats --all` when projects.json is empty or missing; running stats in a fresh project where no session was ever recorded so no project db exists.","commonSituations":"Pointing --crawl-dir at the wrong parent directory; using --all on a brand-new machine before ever running crush; projects.json lost after wiping the data dir; typos in the crawl path (relative path resolved from an unexpected cwd).","solutions":["Run crush in a project at least once so sessions/projects are recorded, then retry stats.","Verify the --crawl-dir path actually contains project data dirs with crush.db: find <dir> -name crush.db.","Use `crush stats` without flags (default project) or `--all` if projects.json has entries.","Check cwd: relative crawl paths resolve from where the command runs; pass an absolute path."],"exampleFix":"// before\ncrush stats --crawl-dir ./nonexistent\n// after\nfind ~/code -name crush.db 2>/dev/null   # confirm projects exist\ncrush stats --crawl-dir ~/code","handlingStrategy":"validation","validationCode":"func hasProjects(root string) bool {\n\tfound := false\n\tfilepath.WalkDir(root, func(p string, d os.DirEntry, err error) error {\n\t\tif err == nil && d.Name() == \"crush.db\" {\n\t\t\tfound = true\n\t\t\treturn filepath.SkipAll\n\t\t}\n\t\treturn nil\n\t})\n\treturn found\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Confirm at least one crush.db exists under --crawl-dir before running: find <dir> -name crush.db.","Use absolute paths for --crawl-dir to avoid cwd surprises.","Run crush once in a project before expecting stats output.","Check that projects.json exists for the --all path."],"tags":["cli","stats","empty-data"],"backgroundTag":"no-data-found","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}