charmbracelet/crush · error
failed to list sessions: %w
Error message
failed to list sessions: %w
What it means
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.
Source
Thrown at internal/cmd/session.go:149
cfg: cfg,
}
return ctx, svc, func() { conn.Close() }, nil
}
func runSessionList(cmd *cobra.Command, _ []string) error {
event.SetNonInteractive(true)
ctx, svc, cleanup, err := sessionSetup(cmd)
if err != nil {
return err
}
defer cleanup()
event.SessionListed(sessionListJSON)
list, err := svc.sessions.List(ctx)
if err != nil {
return fmt.Errorf("failed to list sessions: %w", err)
}
if sessionListJSON {
out := cmd.OutOrStdout()
output := make([]sessionJSON, len(list))
for i, s := range list {
output[i] = sessionJSON{
ID: session.HashID(s.ID),
UUID: s.ID,
Title: s.Title,
Created: time.Unix(s.CreatedAt, 0).Format(time.RFC3339),
Modified: time.Unix(s.UpdatedAt, 0).Format(time.RFC3339),
}
}
enc := json.NewEncoder(out)
enc.SetEscapeHTML(false)
return enc.Encode(output)
}View on GitHub (pinned to 7944b8e522)
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
Defensive patterns
Strategy: retry
Validate before calling
// confirm DB file is reachable and not locked before querying
dbPath := filepath.Join(dataDir, "crush.db")
if _, err := os.Stat(dbPath); err != nil {
return fmt.Errorf("database file missing: %w", err)
} Try / catch
var list []session.Session
var err error
for i := 0; i < 3; i++ {
list, err = svc.sessions.List(ctx)
if err == nil || !errors.Is(err, sqlite.ErrLocked) {
break
}
time.Sleep(100 * time.Millisecond << i)
}
if err != nil {
return fmt.Errorf("failed to list sessions: %w", err)
} Prevention
- 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
When it happens
Trigger: svc.sessions.List(ctx) returns an error: SQL syntax/query mismatch, database locked/corrupted, or context canceled while querying.
Common situations: Corrupted or partially migrated database schema; DB locked by another long-running crush process; running out of disk during query.
Related errors
- failed to get session: %w
- error creating file history: %w
- failed to create session for non-interactive mode: %w
- failed to list messages: %w
- failed to delete session: %w
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/edad833e1ff03d55.
Report an issue: GitHub.