{"record":{"id":"ffb36ce71f3e46f7","repo":"benbjohnson/litestream","slug":"encode-page-d-w","errorCode":null,"errorMessage":"encode page %d: %w","messagePattern":"encode page (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"vfs.go","lineNumber":2163,"sourceCode":"\t\t}\n\n\t\t// Encode each dirty page\n\t\tlockPgno := ltx.LockPgno(pageSize)\n\t\tfor _, pgno := range pgnos {\n\t\t\tif pgno == lockPgno {\n\t\t\t\tcontinue // Skip lock page\n\t\t\t}\n\n\t\t\t// Read page data from buffer file\n\t\t\tbufferOff := dirtyOffsets[pgno]\n\t\t\tdata := make([]byte, pageSize)\n\t\t\tif _, err = bufferFile.ReadAt(data, bufferOff); err != nil {\n\t\t\t\terr = fmt.Errorf(\"read page %d from buffer: %w\", pgno, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif err = enc.EncodePage(ltx.PageHeader{Pgno: pgno}, data); err != nil {\n\t\t\t\terr = fmt.Errorf(\"encode page %d: %w\", pgno, err)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\t// Close encoder (writes trailer and page index)\n\t\tif err = enc.Close(); err != nil {\n\t\t\terr = fmt.Errorf(\"close encoder: %w\", err)\n\t\t\treturn\n\t\t}\n\t}()\n\n\treturn pr\n}\n\n// initWriteBuffer initializes the write buffer file for durability.\n// Any existing buffer content is discarded since unsync'd changes are lost on restart.\n// This function acquires f.mu internally.\nfunc (f *VFSFile) initWriteBuffer() error {","sourceCodeStart":2145,"sourceCodeEnd":2181,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/vfs.go#L2145-L2181","documentation":"After a dirty page is read from the write buffer, it is encoded into the LTX file via enc.EncodePage. This error wraps an EncodePage failure for the given page number — the page data could not be serialized or written to the LTX stream, invalidating the in-progress transaction file.","triggerScenarios":"enc.EncodePage(ltx.PageHeader{Pgno: pgno}, data) fails during sync: broken downstream writer (upload failed/cancelled), compression error on a corrupt page image, or disk error writing the staged LTX file.","commonSituations":"Replica upload pipe broken by network failure or context cancellation mid-transaction; ENOSPC on the staging disk; corrupted page data from a failing write buffer volume.","solutions":["Inspect the wrapped error: broken pipe → resolve replica connectivity and retry sync; ENOSPC → free staging disk space.","Ensure sync contexts are not cancelled mid-transaction (adequate shutdown grace period).","Check the write-buffer volume for hardware/filesystem errors if page data reads are also failing.","Retry the transaction — the partial LTX file is discarded and rebuilt on next sync."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := db.Sync(ctx); err != nil {\n    var pageErr string\n    if m := pageRe.FindStringSubmatch(err.Error()); m != nil { pageErr = m[1] } // \"encode page N\"\n    if pageErr != \"\" { /* check upload pipe/disk, then retry sync */ }\n    return err\n}","preventionTips":["Monitor replica upload reliability — most encode failures trace to broken pipes","Keep staging disk below capacity thresholds","Preserve sync context until encoding completes"],"tags":["go","ltx","encoding","pages"],"backgroundTag":"file-write-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"}