ark_serialize/
error.rs

1use ark_std::{fmt, io};
2
3/// This is an error that could occur during serialization
4#[derive(Debug)]
5pub enum SerializationError {
6    /// During serialization, we didn't have enough space to write extra info.
7    NotEnoughSpace,
8    /// During serialization, the data was invalid.
9    InvalidData,
10    /// During serialization, non-empty flags were given where none were
11    /// expected.
12    UnexpectedFlags,
13    /// During serialization, we countered an I/O error.
14    IoError(io::Error),
15}
16
17impl ark_std::error::Error for SerializationError {}
18
19impl From<io::Error> for SerializationError {
20    fn from(e: io::Error) -> SerializationError {
21        SerializationError::IoError(e)
22    }
23}
24
25impl fmt::Display for SerializationError {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
27        match self {
28            SerializationError::NotEnoughSpace => write!(
29                f,
30                "the last byte does not have enough space to encode the extra info bits"
31            ),
32            SerializationError::InvalidData => write!(f, "the input buffer contained invalid data"),
33            SerializationError::UnexpectedFlags => write!(f, "the call expects empty flags"),
34            SerializationError::IoError(err) => write!(f, "I/O error: {:?}", err),
35        }
36    }
37}