{"record":{"id":"edad833e1ff03d55","repo":"charmbracelet/crush","slug":"failed-to-list-sessions-w","errorCode":null,"errorMessage":"failed to list sessions: %w","messagePattern":"failed to list sessions: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/session.go","lineNumber":149,"sourceCode":"\t\tcfg:      cfg,\n\t}\n\treturn ctx, svc, func() { conn.Close() }, nil\n}\n\nfunc runSessionList(cmd *cobra.Command, _ []string) error {\n\tevent.SetNonInteractive(true)\n\n\tctx, svc, cleanup, err := sessionSetup(cmd)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer cleanup()\n\n\tevent.SessionListed(sessionListJSON)\n\n\tlist, err := svc.sessions.List(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to list sessions: %w\", err)\n\t}\n\n\tif sessionListJSON {\n\t\tout := cmd.OutOrStdout()\n\t\toutput := make([]sessionJSON, len(list))\n\t\tfor i, s := range list {\n\t\t\toutput[i] = sessionJSON{\n\t\t\t\tID:       session.HashID(s.ID),\n\t\t\t\tUUID:     s.ID,\n\t\t\t\tTitle:    s.Title,\n\t\t\t\tCreated:  time.Unix(s.CreatedAt, 0).Format(time.RFC3339),\n\t\t\t\tModified: time.Unix(s.UpdatedAt, 0).Format(time.RFC3339),\n\t\t\t}\n\t\t}\n\t\tenc := json.NewEncoder(out)\n\t\tenc.SetEscapeHTML(false)\n\t\treturn enc.Encode(output)\n\t}","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/session.go#L131-L167","documentation":"runSessionList fetches all sessions via the session service. If the underlying SQL query or row scan fails, the error is wrapped as 'failed to list sessions' and the command exits non-zero.","triggerScenarios":"svc.sessions.List(ctx) returns an error: SQL syntax/query mismatch, database locked/corrupted, or context canceled while querying.","commonSituations":"Corrupted or partially migrated database schema; DB locked by another long-running crush process; running out of disk during query.","solutions":["Inspect the wrapped cause (%w chain) in the CLI output for the SQL error","Ensure no other crush process holds a write lock; check for stale -wal/-shm files","Verify DB migrations ran (schema version) or recreate the database as last resort","Retry the command; transient locks resolve once the other process finishes"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// confirm DB file is reachable and not locked before querying\ndbPath := filepath.Join(dataDir, \"crush.db\")\nif _, err := os.Stat(dbPath); err != nil {\n    return fmt.Errorf(\"database file missing: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"var list []session.Session\nvar err error\nfor i := 0; i < 3; i++ {\n    list, err = svc.sessions.List(ctx)\n    if err == nil || !errors.Is(err, sqlite.ErrLocked) {\n        break\n    }\n    time.Sleep(100 * time.Millisecond << i)\n}\nif err != nil {\n    return fmt.Errorf(\"failed to list sessions: %w\", err)\n}","preventionTips":["Stop other crush processes before running read commands against the same DB","Check for stale -wal/-shm journal files after crashes","Keep crush and the database schema version in sync","Ensure adequate free disk space"],"tags":["go","sqlite","session","query"],"backgroundTag":"database-query-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}