use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Cbor(String),
NotCborld(String),
NoTypeTable(u64),
UnsupportedLiteralType(String),
InvalidTermDefinition(String),
ProtectedTermRedefinition(String),
DocumentLoader(String),
UndefinedCompressedContext(u64),
UnknownTermId(u64),
UnknownCompressedValue(u64),
UnrecognizedBytes(String),
InvalidInput(String),
UnsupportedValue(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Cbor(msg) => write!(f, "CBOR error: {msg}"),
Self::NotCborld(msg) => write!(f, "not CBOR-LD: {msg}"),
Self::NoTypeTable(id) => write!(f, "type table not found for registry entry {id}"),
Self::UnsupportedLiteralType(t) => {
write!(f, "unsupported literal type in type table: {t}")
}
Self::InvalidTermDefinition(msg) => write!(f, "invalid term definition: {msg}"),
Self::ProtectedTermRedefinition(term) => {
write!(f, "unexpected redefinition of protected term {term:?}")
}
Self::DocumentLoader(msg) => write!(f, "document loader error: {msg}"),
Self::UndefinedCompressedContext(id) => {
write!(f, "undefined compressed context {id}")
}
Self::UnknownTermId(id) => write!(f, "unknown CBOR-LD term ID {id}"),
Self::UnknownCompressedValue(id) => write!(f, "unknown compressed value {id}"),
Self::UnrecognizedBytes(msg) => write!(f, "unrecognized bytes: {msg}"),
Self::InvalidInput(msg) => write!(f, "invalid input: {msg}"),
Self::UnsupportedValue(msg) => write!(f, "unsupported value: {msg}"),
}
}
}
impl std::error::Error for Error {}