use thiserror::Error;
use mnem_core::error::{CodecError, StoreError};
use mnem_core::id::Cid;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum TransportError {
#[error("car: {0}")]
Car(String),
#[error("cid mismatch: claimed {claimed}, computed {computed}")]
CidMismatch {
claimed: Cid,
computed: Cid,
},
#[error("unsupported hash algorithm: {0:#x}")]
UnsupportedHash(u64),
#[error("declared root not present in body: {root}")]
MissingRoot {
root: Cid,
},
#[error("import exceeded size limit: {observed} > {limit} bytes")]
SizeLimit {
limit: u64,
observed: u64,
},
#[error("codec: {0}")]
Codec(#[from] CodecError),
#[error("store: {0}")]
Store(#[from] StoreError),
#[error("io: {0}")]
Io(#[from] std::io::Error),
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ClientError {
#[error("network: {0}")]
Network(String),
#[error("framing: {0}")]
Framing(#[from] TransportError),
#[error(
"cas mismatch on ref {ref_name:?}: expected old={expected}, server reports actual={actual}"
)]
CasMismatch {
ref_name: String,
expected: Cid,
actual: Cid,
},
#[error("auth failed: {0}")]
Auth(String),
#[error("protocol: {0}")]
Protocol(String),
#[cfg(feature = "client")]
#[error("serde: {0}")]
Serde(String),
}
#[cfg(feature = "client")]
impl From<reqwest::Error> for ClientError {
fn from(e: reqwest::Error) -> Self {
Self::Network(e.to_string())
}
}
#[cfg(feature = "client")]
impl From<serde_json::Error> for ClientError {
fn from(e: serde_json::Error) -> Self {
Self::Serde(e.to_string())
}
}