about summary refs log blame commit diff
path: root/tvix/store/src/errors.rs
blob: 25e87c8aa2396fe8ff93aea44b7dfd2cb28872b3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
                           
                     
                  









                                                   





                                              








                                                                                             
use std::sync::PoisonError;
use thiserror::Error;
use tonic::Status;

/// Errors related to communication with the store.
#[derive(Debug, Error)]
pub enum Error {
    #[error("invalid request: {0}")]
    InvalidRequest(String),

    #[error("internal storage error: {0}")]
    StorageError(String),
}

impl<T> From<PoisonError<T>> for Error {
    fn from(value: PoisonError<T>) -> Self {
        Error::StorageError(value.to_string())
    }
}

impl From<Error> for Status {
    fn from(value: Error) -> Self {
        match value {
            Error::InvalidRequest(msg) => Status::invalid_argument(msg),
            Error::StorageError(msg) => Status::data_loss(format!("storage error: {}", msg)),
        }
    }
}