{"record":{"id":"a6d477a83448b973","repo":"charmbracelet/crush","slug":"failed-to-commit-transaction-w","errorCode":null,"errorMessage":"failed to commit transaction: %w","messagePattern":"failed to commit transaction: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/history/file.go","lineNumber":126,"sourceCode":"\t\t})\n\t\tif txErr != nil {\n\t\t\t// Rollback the transaction\n\t\t\ttx.Rollback()\n\n\t\t\t// Check if this is a uniqueness constraint violation\n\t\t\tif strings.Contains(txErr.Error(), \"UNIQUE constraint failed\") {\n\t\t\t\tif attempt < maxRetries-1 {\n\t\t\t\t\t// If we have retries left, increment version and try again\n\t\t\t\t\tversion++\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn File{}, txErr\n\t\t}\n\n\t\t// Commit the transaction\n\t\tif txErr = tx.Commit(); txErr != nil {\n\t\t\treturn File{}, fmt.Errorf(\"failed to commit transaction: %w\", txErr)\n\t\t}\n\n\t\tfile = s.fromDBItem(dbFile)\n\t\ts.Publish(pubsub.CreatedEvent, file)\n\t\treturn file, nil\n\t}\n\n\treturn file, err\n}\n\nfunc (s *service) Get(ctx context.Context, id string) (File, error) {\n\tdbFile, err := s.q.GetFile(ctx, id)\n\tif err != nil {\n\t\treturn File{}, err\n\t}\n\treturn s.fromDBItem(dbFile), nil\n}\n","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/history/file.go#L108-L144","documentation":"This error wraps a failure that occurred when committing a SQLite transaction while creating a new history (prompt) file entry. The transaction started, all statements inside it succeeded, but tx.Commit() returned an error, so the whole create is rolled back and no File record is persisted. It signals a database-level problem at commit time rather than a query or argument error.","triggerScenarios":"Calling history.Create or CreateVersion (which delegate to createWithVersion) when the underlying SQLite commit fails: disk full, database file locked by another process/connection, I/O error, or the DB connection was closed mid-transaction.","commonSituations":"Disk quota exhaustion on the machine holding the SQLite database; another Crush process holding the DB lock (no lock file coordination); the database file being on a full or read-only volume; a corrupted database file.","solutions":["Check free disk space on the volume holding the SQLite database and free up space if full.","Ensure no other process holds the database lock; close other instances or check the data-dir lock.","Verify the database file is not corrupted by running integrity checking (PRAGMA integrity_check) and restore from backup if needed.","Retry the operation once the underlying transient I/O condition is resolved; inspect the wrapped error (%w) for the concrete SQLite error code."],"exampleFix":"// before\nfile, err := history.Create(ctx, sessionID, prompt)\nif err != nil {\n    return fmt.Errorf(\"create history: %w\", err) // may hide disk-full\n}\n// after\nfile, err := history.Create(ctx, sessionID, prompt)\nif err != nil {\n    if errors.Is(err, sqlite.ErrBusy) || diskFull() {\n        return fmt.Errorf(\"create history: storage unavailable: %w\", err)\n    }\n    return fmt.Errorf(\"create history: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// before creating history entries\nif err := checkDiskSpace(dbDir); err != nil {\n    return fmt.Errorf(\"insufficient storage for history db: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"file, err := history.Create(ctx, sessionID, prompt)\nif err != nil {\n    var sqliteErr sqlite3.Error\n    if errors.As(err, &sqliteErr) {\n        // inspect sqliteErr.Code (Busy, Full, Corrupt) and act\n    }\n    return fmt.Errorf(\"history create failed: %w\", err)\n}","preventionTips":["Monitor free disk space on the database volume before writes.","Ensure only one process accesses the DB at a time (use the data-dir lock).","Log the fully unwrapped error chain to capture the SQLite error code."],"tags":["database","sqlite","transaction","persistence"],"backgroundTag":"sqlite-commit-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}