tendermint_proto/
error.rs

1//! This module defines the various errors that be raised during Protobuf conversions.
2
3use core::{fmt::Display, num::TryFromIntError};
4
5use flex_error::{define_error, DisplayOnly};
6use prost::{DecodeError, EncodeError};
7
8use crate::prelude::*;
9
10define_error! {
11    Error {
12        TryFromProtobuf
13            { reason: String }
14            | e | {
15                format!("error converting message type into domain type: {}",
16                    e.reason)
17            },
18
19        EncodeMessage
20            [ DisplayOnly<EncodeError> ]
21            | _ | { "error encoding message into buffer" },
22
23        DecodeMessage
24            [ DisplayOnly<DecodeError> ]
25            | _ | { "error decoding buffer into message" },
26
27        ParseLength
28            [ DisplayOnly<TryFromIntError> ]
29            | _ | { "error parsing encoded length" },
30    }
31}
32
33impl Error {
34    pub fn try_from<Raw, T, E>(e: E) -> Error
35    where
36        E: Display,
37        T: TryFrom<Raw, Error = E>,
38    {
39        Error::try_from_protobuf(format!("{e}"))
40    }
41}