{"record":{"id":"a7250a4069c2d2a5","repo":"benbjohnson/litestream","slug":"write-initial-txid-file-w","errorCode":null,"errorMessage":"write initial txid file: %w","messagePattern":"write initial txid file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"replica.go","lineNumber":793,"sourceCode":"\t\t\t\t_ = os.Remove(opt.OutputPath + \"-wal\")\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"post-restore integrity check: %w\", err)\n\t\t}\n\t\tr.Logger().Info(\"post-restore integrity check passed\")\n\t}\n\n\t// Enter follow mode if enabled, continuously applying new LTX files.\n\tif opt.Follow {\n\t\tfor _, rd := range rdrs {\n\t\t\tif closer, ok := rd.(io.Closer); ok {\n\t\t\t\t_ = closer.Close()\n\t\t\t}\n\t\t}\n\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()","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/replica.go#L775-L811","documentation":"Before entering follow mode, WriteTXIDFile failed to record the initial max TXID to the <db>-txid sidecar. Without it, a restart cannot resume following; causes are permission or disk errors at the output path.","triggerScenarios":"Thrown at replica.go:793 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check write permissions and disk space at the output location","Retry the restore with -follow"],"exampleFix":null,"handlingStrategy":"retry","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"}