Skip to main content

PageError

Enum PageError 

Source
#[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, }, InvalidPageId { page_id: u64, }, InvalidSuperblock, }
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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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.

Fields

§size: usize

The rejected size, in bytes.

§

BadMagic

The page’s leading magic bytes did not match. The block is not a page-db page, or its first bytes are corrupt.

Fields

§found: u32

The magic value read from disk.

§expected: u32

The magic value this build writes.

§

UnsupportedVersion

The page’s format version is newer than this build understands.

Fields

§found: u16

The version read from disk.

§supported: u16

The version this build writes and can read.

§

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

§page_id: u64

The id of the slot that was read.

§stored: u32

The checksum stored in the page header.

§computed: u32

The checksum recomputed over the page on read.

§

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

§requested: u64

The slot id that was read.

§found: u64

The id stamped in the page header found there.

§

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

§page_id: u64

The slot id that was read.

§got: usize

The number of bytes actually read.

§page_size: usize

The configured page size.

§

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.

Fields

§capacity: usize

The pool’s frame capacity.

§

InvalidPageId

An id handed to the allocator’s free is not one it could have allocated: it is the reserved superblock (page 0), or it is beyond the high-water mark of pages ever allocated.

Fields

§page_id: u64

The rejected id.

§

InvalidSuperblock

The file’s page 0 is not a valid allocator superblock. The file was not initialized by the allocator, or its superblock is corrupt.

Trait Implementations§

Source§

impl Debug for PageError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PageError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for PageError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for PageError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.