ecksport_codec/
errors.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4#[non_exhaustive]
5pub enum CodecError {
6    #[error("provided input was too short")]
7    InputTooShort,
8
9    #[error("container size too large (entries {0})")]
10    ContainerTooLarge(usize),
11
12    #[error("bytes leftover in container ({0} remaining in {1})")]
13    LeftoverBytes(usize, usize),
14
15    #[error("tried to parse non-UTF-8 bytes as string")]
16    NonUtf8String,
17
18    #[cfg(feature = "as-borsh")]
19    #[error("borsh: {0}")]
20    Borsh(borsh::io::Error),
21
22    #[cfg(feature = "as-serde-cbor")]
23    #[error("cbor: {0}")]
24    SerdeCbor(serde_cbor::error::Error),
25
26    #[cfg(feature = "as-serde-json")]
27    #[error("json: {0}")]
28    SerdeJson(serde_json::Error),
29
30    #[error("{0}")]
31    Other(String),
32
33    #[error("{0}: {1}")]
34    OtherNamed(&'static str, String),
35}
36
37impl CodecError {
38    /// Creates an "other" variant with some fixed name tag.
39    pub fn named<T: ToString>(name: &'static str, v: T) -> Self {
40        Self::OtherNamed(name, v.to_string())
41    }
42}