{"record":{"id":"efd57418f1063535","repo":"spacejam/sled","slug":"failed-to-fill-whole-buffer","errorCode":null,"errorMessage":"failed to fill whole buffer","messagePattern":"failed to fill whole buffer","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/heap.rs","lineNumber":465,"sourceCode":"    pub(super) fn read_exact_at(\n        file: &fs::File,\n        mut buf: &mut [u8],\n        mut offset: u64,\n    ) -> io::Result<()> {\n        while !buf.is_empty() {\n            match maybe!(file.seek_read(buf, offset)) {\n                Ok(0) => break,\n                Ok(n) => {\n                    let tmp = buf;\n                    buf = &mut tmp[n..];\n                    offset += n as u64;\n                }\n                Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}\n                Err(e) => return Err(annotate!(e)),\n            }\n        }\n        if !buf.is_empty() {\n            Err(annotate!(io::Error::new(\n                io::ErrorKind::UnexpectedEof,\n                \"failed to fill whole buffer\"\n            )))\n        } else {\n            Ok(())\n        }\n    }\n\n    pub(super) fn write_all_at(\n        file: &fs::File,\n        mut buf: &[u8],\n        mut offset: u64,\n    ) -> io::Result<()> {\n        while !buf.is_empty() {\n            match maybe!(file.seek_write(buf, offset)) {\n                Ok(0) => {\n                    return Err(annotate!(io::Error::new(\n                        io::ErrorKind::WriteZero,","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/spacejam/sled/blob/e449d17111f4a097e1c66b6db241962ccb6a4136/src/heap.rs#L447-L483","documentation":"read_exact_at loops pwrite/pread-style reads until the buffer is filled; if the file ends before the requested bytes are available, it returns UnexpectedEof with this message. It means the caller expected data at a given offset that does not exist on disk.","triggerScenarios":"Reading at an offset beyond the end of the file: truncated/corrupted database file, a crash that lost a write the in-memory state assumed was durable, or wrong offset bookkeeping.","commonSituations":"Recovering after a crash where file length metadata says data exists but writes were never flushed; disk full conditions truncating files; copying a database file partially.","solutions":["Restore the database file from backup, as the expected bytes are missing","Run filesystem checks (fsck) and confirm the file size matches expectations","If a crash caused it, re-open and let the recovery/replay path rebuild, or re-import from an export","Free disk space / fix storage issues that led to truncation before retrying"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify file size covers the offsets you expect to read\nlet len = file.metadata()?.len();\nif offset + buf.len() as u64 > len { return Err(anyhow!(\"read beyond EOF: file truncated\")); }","typeGuard":null,"tryCatchPattern":"match Db::open(&path) {\n    Ok(db) => db,\n    Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => {\n        restore_backup(&path)?; // data is missing on disk\n        Db::open(&path)?\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Ensure fsync'd, clean shutdowns before killing or migrating the process","Monitor free disk space; truncation often follows disk-full events","Never copy database files while the database is open","Keep backups and verify restored files' sizes/checksums"],"tags":["rust","io","eof","storage"],"backgroundTag":"file-read-failed","analyzedSha":"e449d17111f4a097e1c66b6db241962ccb6a4136","analyzedAt":"2026-09-12T01:23:10.985Z","contentChangedAt":"2026-09-12T01:23:10.985Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}