{"record":{"id":"327e908041ac212f","repo":"benbjohnson/litestream","slug":"read-page-size-from-database-header-w","errorCode":null,"errorMessage":"read page size from database header: %w","messagePattern":"read page size from database header: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"replica.go","lineNumber":817,"sourceCode":"}\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\n\t}\n\n\tr.Logger().Info(\"entering follow mode\", \"output\", outputPath, \"txid\", lastTXID, \"interval\", interval)\n\n\tticker := time.NewTicker(interval)\n\tdefer ticker.Stop()\n\n\tvar consecutiveErrors int\n\tfor {\n\t\tselect {","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/replica.go#L799-L835","documentation":"follow() failed to read the page size from the SQLite header of the restored database (offset 16, 2 bytes, big-endian). The file is too short or the header magic is invalid — the restore produced a non-database file.","triggerScenarios":"Thrown at replica.go:817 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the restored file is a valid SQLite database (sqlite3 pragma header_check or file inspection)","Re-run the restore from a known-good replica state"],"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"}