1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum Error {
9 Cbor(String),
11 NotCborld(String),
13 NoTypeTable(u64),
15 UnsupportedLiteralType(String),
17 InvalidTermDefinition(String),
19 ProtectedTermRedefinition(String),
21 DocumentLoader(String),
23 UndefinedCompressedContext(u64),
25 UnknownTermId(u64),
27 UnknownCompressedValue(u64),
29 UnrecognizedBytes(String),
31 InvalidInput(String),
33 UnsupportedValue(String),
35}
36
37impl fmt::Display for Error {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 match self {
40 Self::Cbor(msg) => write!(f, "CBOR error: {msg}"),
41 Self::NotCborld(msg) => write!(f, "not CBOR-LD: {msg}"),
42 Self::NoTypeTable(id) => write!(f, "type table not found for registry entry {id}"),
43 Self::UnsupportedLiteralType(t) => {
44 write!(f, "unsupported literal type in type table: {t}")
45 }
46 Self::InvalidTermDefinition(msg) => write!(f, "invalid term definition: {msg}"),
47 Self::ProtectedTermRedefinition(term) => {
48 write!(f, "unexpected redefinition of protected term {term:?}")
49 }
50 Self::DocumentLoader(msg) => write!(f, "document loader error: {msg}"),
51 Self::UndefinedCompressedContext(id) => {
52 write!(f, "undefined compressed context {id}")
53 }
54 Self::UnknownTermId(id) => write!(f, "unknown CBOR-LD term ID {id}"),
55 Self::UnknownCompressedValue(id) => write!(f, "unknown compressed value {id}"),
56 Self::UnrecognizedBytes(msg) => write!(f, "unrecognized bytes: {msg}"),
57 Self::InvalidInput(msg) => write!(f, "invalid input: {msg}"),
58 Self::UnsupportedValue(msg) => write!(f, "unsupported value: {msg}"),
59 }
60 }
61}
62
63impl std::error::Error for Error {}