{"record":{"id":"5553b722b1e9cb79","repo":"benbjohnson/litestream","slug":"open-database-for-follow-w","errorCode":null,"errorMessage":"open database for follow: %w","messagePattern":"open database for follow: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"replica.go","lineNumber":807,"sourceCode":"\t\trdrs = nil\n\n\t\tmaxTXID := infos[len(infos)-1].MaxTXID\n\t\tif err := WriteTXIDFile(opt.OutputPath, maxTXID); err != nil {\n\t\t\treturn fmt.Errorf(\"write initial txid file: %w\", err)\n\t\t}\n\t\treturn r.follow(ctx, opt.OutputPath, maxTXID, opt.FollowInterval)\n\t}\n\n\treturn nil\n}\n\n// follow enters a continuous restore loop, polling for new LTX files and\n// applying them to the restored database. It blocks until the context is\n// cancelled (e.g. Ctrl+C). Returns nil on clean shutdown.\nfunc (r *Replica) follow(ctx context.Context, outputPath string, lastTXID ltx.TXID, interval time.Duration) error {\n\tf, err := os.OpenFile(outputPath, os.O_RDWR, 0)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"open database for follow: %w\", err)\n\t}\n\tdefer func() {\n\t\t_ = f.Sync()\n\t\t_ = f.Close()\n\t}()\n\n\t// Read page size from SQLite header (offset 16, 2 bytes, big-endian).\n\tvar buf [2]byte\n\tif _, err := f.ReadAt(buf[:], 16); err != nil {\n\t\treturn fmt.Errorf(\"read page size from database header: %w\", err)\n\t}\n\tpageSize := uint32(buf[0])<<8 | uint32(buf[1])\n\tif pageSize == 1 {\n\t\tpageSize = 65536\n\t}\n\n\tif interval <= 0 {\n\t\tinterval = DefaultFollowInterval","sourceCodeStart":789,"sourceCodeEnd":825,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/replica.go#L789-L825","documentation":"Wraps file-open failure in Replica.follow at the start of the continuous restore loop. Fires when the restored database file cannot be opened for follow mode (polling and applying new LTX files), aborting continuous restore.","triggerScenarios":"Thrown at replica.go:807 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the restored file exists and is writable by the litestream process","Re-run the restore"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}