lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

error.rs (2192B)


      1 #[cfg(not(feature = "std"))]
      2 use alloc::string::String;
      3 use core::fmt;
      4 
      5 #[derive(Debug, Clone, PartialEq, Eq)]
      6 pub enum RadrootsSimplexChatProtoError {
      7     EmptyInput,
      8     InvalidUtf8,
      9     InvalidJson(String),
     10     InvalidVersionRange(String),
     11     InvalidBase64Url { field: &'static str, value: String },
     12     MissingField(&'static str),
     13     InvalidField(&'static str),
     14     InvalidCompressedEnvelope(String),
     15     CompressedMessageTooLarge(usize),
     16     CompressionUnavailable,
     17     UnsupportedBinaryMessage,
     18 }
     19 
     20 impl fmt::Display for RadrootsSimplexChatProtoError {
     21     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     22         match self {
     23             Self::EmptyInput => write!(f, "empty SimpleX chat input"),
     24             Self::InvalidUtf8 => write!(f, "invalid UTF-8 in SimpleX chat input"),
     25             Self::InvalidJson(error) => write!(f, "invalid SimpleX chat JSON: {error}"),
     26             Self::InvalidVersionRange(range) => {
     27                 write!(f, "invalid SimpleX chat version range `{range}`")
     28             }
     29             Self::InvalidBase64Url { field, value } => {
     30                 write!(f, "invalid base64url value for `{field}`: `{value}`")
     31             }
     32             Self::MissingField(field) => write!(f, "missing required SimpleX chat field `{field}`"),
     33             Self::InvalidField(field) => write!(f, "invalid SimpleX chat field `{field}`"),
     34             Self::InvalidCompressedEnvelope(error) => {
     35                 write!(f, "invalid compressed SimpleX chat envelope: {error}")
     36             }
     37             Self::CompressedMessageTooLarge(length) => {
     38                 write!(f, "compressed SimpleX chat message exceeds limit: {length}")
     39             }
     40             Self::CompressionUnavailable => {
     41                 write!(
     42                     f,
     43                     "SimpleX chat compression support requires the `std` feature"
     44                 )
     45             }
     46             Self::UnsupportedBinaryMessage => {
     47                 write!(
     48                     f,
     49                     "binary SimpleX chat messages are not supported by this crate"
     50                 )
     51             }
     52         }
     53     }
     54 }
     55 
     56 #[cfg(feature = "std")]
     57 impl std::error::Error for RadrootsSimplexChatProtoError {}