unc_chunks_primitives/
error.rs

1use std::fmt;
2
3use unc_primitives::errors::EpochError;
4
5#[derive(Debug)]
6pub enum Error {
7    InvalidPartMessage,
8    InvalidChunkPartId,
9    InvalidChunkShardId,
10    InvalidMerkleProof,
11    InvalidChunkSignature,
12    InvalidChunkHeader,
13    InvalidChunk,
14    DuplicateChunkHeight,
15    UnknownChunk,
16    KnownPart,
17    ChainError(unc_chain_primitives::Error),
18    IOError(std::io::Error),
19}
20
21impl std::error::Error for Error {}
22
23impl fmt::Display for Error {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
25        write!(f, "{:?}", self)
26    }
27}
28
29impl From<std::io::Error> for Error {
30    fn from(err: std::io::Error) -> Self {
31        Error::IOError(err)
32    }
33}
34
35impl From<unc_chain_primitives::Error> for Error {
36    fn from(err: unc_chain_primitives::Error) -> Self {
37        Error::ChainError(err)
38    }
39}
40
41impl From<EpochError> for Error {
42    fn from(err: EpochError) -> Self {
43        Error::ChainError(err.into())
44    }
45}