{"record":{"id":"10c0e9b88d5d606f","repo":"charmbracelet/crush","slug":"failed-to-delete-session-w","errorCode":null,"errorMessage":"failed to delete session: %w","messagePattern":"failed to delete session: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/session.go","lineNumber":305,"sourceCode":"\nfunc runSessionDelete(cmd *cobra.Command, args []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.SessionDeletedCommand(sessionDeleteJSON)\n\n\tsess, err := resolveSessionID(ctx, svc.sessions, args[0])\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif err := svc.sessions.Delete(ctx, sess.ID); err != nil {\n\t\treturn fmt.Errorf(\"failed to delete session: %w\", err)\n\t}\n\n\tout := cmd.OutOrStdout()\n\tif sessionDeleteJSON {\n\t\tenc := json.NewEncoder(out)\n\t\tenc.SetEscapeHTML(false)\n\t\treturn enc.Encode(sessionMutationResult{\n\t\t\tID:      session.HashID(sess.ID),\n\t\t\tUUID:    sess.ID,\n\t\t\tTitle:   sess.Title,\n\t\t\tDeleted: true,\n\t\t})\n\t}\n\n\tfmt.Fprintf(out, \"Deleted session %s\\n\", session.HashID(sess.ID)[:12])\n\treturn nil\n}\n","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/session.go#L287-L323","documentation":"runSessionDelete resolves the target session then calls sessions.Delete. If the DB delete (including cascading message removal) fails, the error is wrapped as 'failed to delete session'. Note: a non-existent ID fails earlier in resolveSessionID, so this is almost always a storage-layer failure.","triggerScenarios":"svc.sessions.Delete(ctx, sess.ID) errors: SQL failure, foreign-key/constraint issue, DB locked by another process, corrupted DB, or canceled context mid-transaction.","commonSituations":"SQLite write lock held by a running crush session; read-only filesystem or data dir; disk full preventing the transaction from committing.","solutions":["Ensure no other crush process is running (write lock) and retry","Check the data dir/filesystem is writable and has free disk space","Inspect the wrapped error chain for the exact SQL error","As a last resort back up and repair/recreate the database"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check write access to the DB file before deleting\ndbPath := filepath.Join(dataDir, \"crush.db\")\nif f, err := os.OpenFile(dbPath, os.O_WRONLY, 0); err != nil {\n    return fmt.Errorf(\"database not writable: %w\", err)\n} else {\n    f.Close()\n}","typeGuard":null,"tryCatchPattern":"if err := svc.sessions.Delete(ctx, sess.ID); err != nil {\n    slog.Error(\"Delete failed\", \"session\", sess.ID, \"error\", err)\n    return fmt.Errorf(\"failed to delete session: %w\", err)\n}","preventionTips":["Ensure no running crush session holds the SQLite write lock","Verify data dir/filesystem is writable and has free space","Back up the DB before bulk deletions","Confirm the session exists via resolveSessionID before delete (already done in flow)"],"tags":["go","sqlite","session","delete"],"backgroundTag":"database-write-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}