#[non_exhaustive]pub enum PageError {
Io(Error),
InvalidPageSize {
size: usize,
},
BadMagic {
found: u32,
expected: u32,
},
UnsupportedVersion {
found: u16,
supported: u16,
},
ChecksumMismatch {
page_id: u64,
stored: u32,
computed: u32,
},
MisdirectedPage {
requested: u64,
found: u64,
},
ShortRead {
page_id: u64,
got: usize,
page_size: usize,
},
BufferPoolExhausted {
capacity: usize,
},
}Expand description
Everything that can go wrong reading, writing, or framing a page.
The variants split into two families: I/O failures from the underlying file
(PageError::Io) and integrity failures detected while validating a page
against its header. The latter are the interesting ones — they are how a
torn write, a bit-rotted block, or a misdirected read surfaces as a value
instead of silently corrupting the layer above.
The type is #[non_exhaustive]: later releases may add variants (for
example as the allocator and buffer pool land), so match with a wildcard
arm.
§Examples
use page_db::PageError;
// I/O errors convert in with `?` via the `From<std::io::Error>` impl.
fn classify(err: &PageError) -> &'static str {
match err {
PageError::Io(_) => "io",
PageError::ChecksumMismatch { .. } => "corruption",
_ => "other",
}
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Io(Error)
An I/O operation on the underlying file failed.
The source std::io::Error is preserved, so callers that need the OS
error kind (for example to distinguish io::ErrorKind::NotFound on
open) can reach it through std::error::Error::source or by matching
this variant directly.
InvalidPageSize
A requested page size is not a power of two within
MIN_PAGE_SIZE..=MAX_PAGE_SIZE.
BadMagic
The page’s leading magic bytes did not match. The block is not a page-db page, or its first bytes are corrupt.
UnsupportedVersion
The page’s format version is newer than this build understands.
Fields
ChecksumMismatch
The page’s stored CRC32C did not match the checksum recomputed over its bytes. The page is corrupt — a torn write, bit rot, or a wrong byte.
Fields
MisdirectedPage
The page read back from a slot carries a different id than the one requested. This catches a misdirected read or write — the file handed back the wrong block.
Fields
ShortRead
A read returned fewer bytes than a whole page. The slot is past the end of the file, or the file’s length is not a whole number of pages.
Fields
BufferPoolExhausted
A buffer pool could not admit another page because every frame is pinned. The pool refuses to evict a pinned page, so this is the signal to release some pins or size the pool larger.
Trait Implementations§
Source§impl Error for PageError
impl Error for PageError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()