{"record":{"id":"b0d16da599653c17","repo":"charmbracelet/crush","slug":"failed-to-list-messages-w-b0d16d","errorCode":null,"errorMessage":"failed to list messages: %w","messagePattern":"failed to list messages: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/session.go","lineNumber":278,"sourceCode":"func runSessionShow(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.SessionShown(sessionShowJSON)\n\n\tsess, err := resolveSessionID(ctx, svc.sessions, args[0])\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tmsgs, err := svc.messages.List(ctx, sess.ID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to list messages: %w\", err)\n\t}\n\n\tmsgPtrs := messagePtrs(msgs)\n\tif sessionShowJSON {\n\t\treturn outputSessionJSON(cmd.OutOrStdout(), sess, msgPtrs)\n\t}\n\treturn outputSessionHuman(ctx, svc.cfg, sess, msgPtrs)\n}\n\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","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/session.go#L260-L296","documentation":"runSessionShow, after resolving the session, lists its messages via the message service. Any failure in that query (scan error, DB issue, context cancellation) is wrapped as 'failed to list messages'.","triggerScenarios":"svc.messages.List(ctx, sess.ID) errors: messages table schema mismatch, corrupted rows (invalid JSON in message content), DB lock, or canceled context.","commonSituations":"Database written by a newer/older crush version with a different messages schema; a row with malformed JSON content that fails to unmarshal during scan; concurrent write lock.","solutions":["Read the wrapped underlying error to distinguish scan/unmarshal failures from connection issues","Check crush version vs the DB schema version; upgrade crush or migrate the DB","Back up the DB, then inspect/repair the messages table for the given session","Ensure no concurrent crush process is holding a write lock"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"msgs, err := svc.messages.List(ctx, sess.ID)\nif err != nil {\n    if errors.Is(err, context.Canceled) {\n        return err\n    }\n    slog.Error(\"Failed to load messages\", \"session\", sess.ID, \"error\", err)\n    return fmt.Errorf(\"failed to list messages: %w\", err)\n}","preventionTips":["Run the same crush version that wrote the database","Back up the DB before manual edits to the messages table","Watch for unmarshal errors on message content indicating corrupt rows","Avoid concurrent writers on the same data dir"],"tags":["go","sqlite","messages","session"],"backgroundTag":"database-query-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}