{"record":{"id":"5a0cfe6623608e54","repo":"benbjohnson/litestream","slug":"decode-header-w","errorCode":null,"errorMessage":"decode header: %w","messagePattern":"decode header: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"replica.go","lineNumber":955,"sourceCode":"\n// applyLTXFile applies a single LTX file's pages to the database file.\n// This follows the same pattern as Hydrator.ApplyLTX (vfs.go:712-747).\n//\n// To prevent concurrent SQLite readers from seeing partial updates, we acquire\n// an exclusive file lock before writing. We also rewrite the SQLite header\n// (bytes 18-19) to indicate DELETE journal mode instead of WAL mode, and\n// randomize the schema change counter (bytes 24-27) to invalidate cached\n// schemas in other connections.\nfunc (r *Replica) applyLTXFile(ctx context.Context, f *os.File, info *ltx.FileInfo, pageSize uint32) error {\n\trc, err := r.Client.OpenLTXFile(ctx, info.Level, info.MinTXID, info.MaxTXID, 0, 0)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"open ltx file: %w\", err)\n\t}\n\tdefer rc.Close()\n\n\tdec := ltx.NewDecoder(rc)\n\tif err := dec.DecodeHeader(); err != nil {\n\t\treturn fmt.Errorf(\"decode header: %w\", err)\n\t}\n\n\thdr := dec.Header()\n\n\tif err := internal.LockFileExclusive(f); err != nil {\n\t\treturn fmt.Errorf(\"acquire exclusive lock: %w\", err)\n\t}\n\tdefer internal.UnlockFile(f)\n\n\tfor {\n\t\tvar phdr ltx.PageHeader\n\t\tdata := make([]byte, pageSize)\n\t\tif err := dec.DecodePage(&phdr, data); err == io.EOF {\n\t\t\tbreak\n\t\t} else if err != nil {\n\t\t\treturn fmt.Errorf(\"decode page: %w\", err)\n\t\t}\n","sourceCodeStart":937,"sourceCodeEnd":973,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/replica.go#L937-L973","documentation":"ltx.Decoder.DecodeHeader failed on the opened LTX stream in applyLTXFile. The downloaded file is not a valid LTX — truncated body, bad magic, or unsupported version — so its pages cannot be safely applied.","triggerScenarios":"Thrown at replica.go:955 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Delete and re-upload the corrupted LTX object","Inspect it with 'litestream ltx -level N' to confirm corruption"],"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"}