use std::any::type_name;
use thiserror::Error;
#[derive(Debug, Error)]
#[error("Number larger than {ty}.")]
pub struct NumberOutOfRange {
pub ty: &'static str,
}
impl NumberOutOfRange {
pub fn new<T>() -> Self {
Self {
ty: type_name::<T>(),
}
}
}
#[derive(Debug, Error)]
#[error("Number not minimally encoded.")]
pub struct NumberNotMinimal;
#[derive(Debug, Error)]
#[error("Length out of range when decoding {ty}.")]
pub struct LengthOutOfRange {
pub ty: &'static str,
}
impl LengthOutOfRange {
pub fn new<T>() -> Self {
Self {
ty: type_name::<T>(),
}
}
}
#[derive(Debug, Error)]
#[error("Unexpected cbor code `0x{code:x}` when decoding `{ty}`.")]
pub struct UnexpectedCode {
pub code: u8,
pub ty: &'static str,
}
impl UnexpectedCode {
pub fn new<T>(code: u8) -> Self {
Self {
code,
ty: type_name::<T>(),
}
}
}
#[derive(Debug, Error)]
#[error("Unexpected key `{key}` when decoding `{ty}`.")]
pub struct UnexpectedKey {
pub key: String,
pub ty: &'static str,
}
impl UnexpectedKey {
pub fn new<T>(key: String) -> Self {
Self {
key,
ty: type_name::<T>(),
}
}
}
#[derive(Debug, Error)]
#[error("Missing key `{key}` for decoding `{ty}`.")]
pub struct MissingKey {
pub key: &'static str,
pub ty: &'static str,
}
impl MissingKey {
pub fn new<T>(key: &'static str) -> Self {
Self {
key,
ty: type_name::<T>(),
}
}
}
#[derive(Debug, Error)]
#[error("Unknown cbor tag `{0}`.")]
pub struct UnknownTag(pub u64);
#[derive(Debug, Error)]
#[error("Unexpected end of file.")]
pub struct UnexpectedEof;
#[derive(Debug, Error)]
#[error("Invalid Cid prefix: {0}")]
pub struct InvalidCidPrefix(pub u8);
#[derive(Debug, Error)]
#[error("Duplicate map key.")]
pub struct DuplicateKey;