{"record":{"id":"7d378206c9457170","repo":"benbjohnson/litestream","slug":"cannot-determine-current-position-w","errorCode":null,"errorMessage":"cannot determine current position: %w","messagePattern":"cannot determine current position: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"replica.go","lineNumber":195,"sourceCode":"\t}()\n\n\tif err := ctx.Err(); err != nil {\n\t\treturn result, context.Cause(ctx)\n\t}\n\n\t// Calculate current replica position, if unknown.\n\tif r.Pos().IsZero() {\n\t\tpos, err := r.calcPos(ctx)\n\t\tif err != nil {\n\t\t\treturn result, fmt.Errorf(\"calc pos: %w\", err)\n\t\t}\n\t\tr.SetPos(pos)\n\t}\n\n\t// Find current position of database.\n\tdpos, err := r.db.Pos()\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"cannot determine current position: %w\", err)\n\t} else if dpos.IsZero() {\n\t\treturn result, errReplicaWaitForData\n\t}\n\n\tr.Logger().Debug(\"replica sync\",\n\t\tslog.Group(\"txid\",\n\t\t\tslog.String(\"replica\", r.Pos().TXID.String()),\n\t\t\tslog.String(\"db\", dpos.TXID.String()),\n\t\t))\n\n\t// Replicate all L0 LTX files since last replica position.\n\tfor txID, syncedFileN := r.Pos().TXID+1, 0; txID <= dpos.TXID; txID = r.Pos().TXID + 1 {\n\t\tif maxSyncLTXFiles > 0 && syncedFileN >= maxSyncLTXFiles {\n\t\t\tresult.limited = true\n\t\t\t// Uploads succeeded, so record sync health; otherwise a\n\t\t\t// sustained backlog reads as unhealthy while progressing.\n\t\t\tr.db.RecordSuccessfulSync()\n\t\t\tr.Logger().Debug(\"replica sync limited\",","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/replica.go#L177-L213","documentation":"This error wraps a failure from r.db.Pos(), which reads the database's current replication position (TXID/page) from the local SQLite database header and WAL. Litestream needs the current position in syncOnce to compute which LTX frames still need uploading; if reading that position fails, the sync cannot proceed and the underlying cause is wrapped so the real error is preserved.","triggerScenarios":"Replica.syncOnce (or sync) runs while the underlying DB handle cannot read its position — e.g. the database file was deleted/moved, the DB is not open, WAL/SHM files are unreadable, or the db metadata read returns an I/O or SQLite error. Callers: TestReplica_SyncOnceLimitsLTXFiles and Replica.sync.","commonSituations":"Database file removed or corrupted while litestream is running; DB closed concurrently; running on a filesystem where the WAL/SHM can't be read (permissions, NFS issues); pointing a replica at a database path that no longer exists.","solutions":["Check the wrapped cause (%w) to see the underlying db.Pos() error and fix that (missing file, permissions, corruption).","Verify the database path in config still exists and litestream has read/write access to the DB, WAL, and SHM files.","Restart litestream so the DB handle is re-opened against the current database file.","If local LTX/DB state is corrupted, run `litestream reset` for the database before resuming replication."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before syncing, confirm the DB is open and files are readable\nif _, err := os.Stat(dbPath + \"-wal\"); err != nil {\n    return fmt.Errorf(\"db wal unreadable: %w\", err)\n}\npos, err := db.Pos()\nif err != nil || pos.IsZero() {\n    return fmt.Errorf(\"db not ready for sync: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := replica.Sync(ctx); err != nil {\n    var wrapped interface{ Unwrap() error }\n    if errors.As(err, &cause) && strings.Contains(err.Error(), \"cannot determine current position\") {\n        log.Printf(\"db position unreadable, resetting local state: %v\", cause)\n    }\n}","preventionTips":["Keep the DB, WAL, and SHM files on a reliable local filesystem with correct permissions","Avoid deleting or moving the database while litestream is replicating","Monitor the wrapped cause of sync errors, not just the top-level message"],"tags":["replication","database","sync"],"backgroundTag":"database-query-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}