1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use super::*;

/// Errors involving app entry creation
#[derive(Debug, Clone, PartialEq)]
pub enum EntryError {
    /// The entry is too large to be created
    EntryTooLarge(usize),

    /// SerializedBytes passthrough
    SerializedBytes(SerializedBytesError),
}

impl std::error::Error for EntryError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            EntryError::EntryTooLarge(_) => None,
            EntryError::SerializedBytes(e) => e.source(),
        }
    }
}

impl From<SerializedBytesError> for EntryError {
    fn from(e: SerializedBytesError) -> Self {
        Self::SerializedBytes(e)
    }
}

impl core::fmt::Display for EntryError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            EntryError::EntryTooLarge(bytes)=> write!(
                f,
                "Attempted to create an Entry whose size exceeds the limit.\nEntry size: {}\nLimit: {}",
                bytes,
                ENTRY_SIZE_LIMIT
            ),
            EntryError::SerializedBytes(s) => s.fmt(f),
        }
    }
}