sqlite-parser/src/error.rs

24 lines
752 B
Rust

use std::fmt;
/// Representation of our possible errors.
/// Each variant will contain a string for more
/// detailed information
#[derive(Debug)]
pub enum Error {
/// An error related to the first 16 bytes
HeaderString(String),
/// An error parsing the page size
InvalidPageSize(String),
}
impl fmt::Display for Error {
/// This will be called whenever we print
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::HeaderString(v) => write!(f, "Unexpected bytes at start of file, expected the magic string 'SQLite format 3\u{0}', found {:?}", v),
Self::InvalidPageSize(msg) => write!(f, "Invalid page size, {}", msg),
}
}
}
impl std::error::Error for Error {}