prost_simple_rpc/
error.rs

1//! Error type definitions for errors that can occur during RPC interactions.
2use std::result;
3
4use failure;
5use prost;
6
7/// A convenience type alias for creating a `Result` with the error being of type `Error`.
8pub type Result<A, E> = result::Result<A, Error<E>>;
9
10/// An error has occurred.
11#[derive(Clone, Debug, Eq, Fail, PartialEq)]
12pub enum Error<E>
13where
14    E: failure::Fail,
15{
16    /// An error occurred during the execution of a (server) RPC endpoint or a (client) RPC transfer
17    /// mechanism.
18    #[fail(display = "Execution error: {}", error)]
19    Execution {
20        /// The underlying execution error.
21        #[cause]
22        error: E,
23    },
24    /// An error occurred during input decoding.
25    #[fail(display = "Decode error: {}", error)]
26    Decode {
27        /// The underlying decode error.
28        #[cause]
29        error: prost::DecodeError,
30    },
31    /// An error occurred during output encoding.
32    #[fail(display = "Encode error: {}", error)]
33    Encode {
34        /// The underlying encode error.
35        #[cause]
36        error: prost::EncodeError,
37    },
38}
39
40impl<E> Error<E>
41where
42    E: failure::Fail,
43{
44    /// Constructs a new execution error.
45    pub fn execution(error: E) -> Self {
46        Error::Execution { error }
47    }
48}
49
50impl<E> From<prost::DecodeError> for Error<E>
51where
52    E: failure::Fail,
53{
54    fn from(error: prost::DecodeError) -> Self {
55        Error::Decode { error }
56    }
57}
58
59impl<E> From<prost::EncodeError> for Error<E>
60where
61    E: failure::Fail,
62{
63    fn from(error: prost::EncodeError) -> Self {
64        Error::Encode { error }
65    }
66}