use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum CodecError {
#[error("provided input was too short")]
InputTooShort,
#[error("container size too large (entries {0})")]
ContainerTooLarge(usize),
#[error("bytes leftover in container ({0} remaining in {1})")]
LeftoverBytes(usize, usize),
#[error("tried to parse non-UTF-8 bytes as string")]
NonUtf8String,
#[cfg(feature = "as-borsh")]
#[error("borsh: {0}")]
Borsh(borsh::io::Error),
#[cfg(feature = "as-serde-cbor")]
#[error("cbor: {0}")]
SerdeCbor(serde_cbor::error::Error),
#[cfg(feature = "as-serde-json")]
#[error("json: {0}")]
SerdeJson(serde_json::Error),
#[error("{0}")]
Other(String),
#[error("{0}: {1}")]
OtherNamed(&'static str, String),
}
impl CodecError {
pub fn named<T: ToString>(name: &'static str, v: T) -> Self {
Self::OtherNamed(name, v.to_string())
}
}