flowlight0 / simpledb-rs

MIT License
0 stars 0 forks source link

Error refactoring #23

Closed flowlight0 closed 4 days ago

flowlight0 commented 4 days ago

Fix #21

This PR introduces a hierarchical enum-based errors. I replaced anyhow::Error with the following error in all the places except driver-related components because I'm not confident about what kind of changes occurs when implementing the remote driver.


#[derive(Error, Debug)]
pub enum TransactionError {
    #[error("LockGiveUpError")]
    LockGiveUpError,

    #[error("BufferAbortError")]
    BufferAbortError,

    #[error("IO error: {0}")]
    IO(#[from] std::io::Error),
}

#[derive(Error, Debug)]
pub enum QueryError {
    #[error("ParseError: {0}")]
    ParseError(ParseError<usize, String, String>),
}

impl From<ParseError<usize, Token<'_>, &str>> for QueryError {
    fn from(value: ParseError<usize, Token, &str>) -> Self {
        QueryError::ParseError(
            value
                .map_token(|token| token.1.to_string())
                .map_error(|error| error.to_string()),
        )
    }
}

#[derive(Error, Debug)]
pub enum ExecutionError {
    #[error("TransactionError: {0}")]
    TransactionError(#[from] TransactionError),

    #[error("QueryError: {0}")]
    QueryError(#[from] QueryError),
}