mod clone;
mod logging;
#[cfg(test)]
mod tests;
use thiserror::*;
use crate::proto;
#[derive(Error, Debug)]
pub enum ClientError {
#[error("Abort(): {0}")]
Internal(String),
#[error("Client not yet initialized")]
NotInitialized,
#[error("Unknown error: {0}")]
Unknown(String),
#[error("Unwrapped option")]
Option,
#[error("Unexpected response {0:?}")]
OptionResponseFailed(Box<Option<proto::response::ClientResp>>),
#[error("Bad string")]
Utf8(#[from] std::str::Utf8Error),
#[error("Undecipherable server message {0:?}")]
DecodeError(#[from] prost::DecodeError),
#[error("Unexpected response {0:?}")]
ResponseFailed(Box<proto::response::ClientResp>),
#[error("Not yet implemented {0:?}")]
NotImplemented(&'static str),
#[error("Can't use both `limit` and `index` arguments")]
BadTableOptions,
#[error("External error: {0:?}")]
ExternalError(#[from] Box<dyn std::error::Error + Send + Sync>),
#[error("Undecipherable proto message")]
ProtoError(#[from] prost::EncodeError),
}
pub type ClientResult<T> = Result<T, ClientError>;
impl From<proto::response::ClientResp> for ClientError {
fn from(value: proto::response::ClientResp) -> Self {
match value {
proto::response::ClientResp::ServerError(x) => ClientError::Internal(x.message),
x => ClientError::ResponseFailed(Box::new(x)),
}
}
}