executor_types/
error.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8use diem_crypto::HashValue;
9use serde::{Deserialize, Serialize};
10use thiserror::Error;
11
12#[derive(Debug, Deserialize, Error, PartialEq, Serialize)]
13/// Different reasons for proposal rejection
14pub enum Error {
15    #[error("Cannot find speculation result for block id {0}")]
16    BlockNotFound(HashValue),
17
18    #[error("Internal error: {:?}", error)]
19    InternalError { error: String },
20
21    #[error("Serialization error: {0}")]
22    SerializationError(String),
23}
24
25impl From<anyhow::Error> for Error {
26    fn from(error: anyhow::Error) -> Self {
27        Self::InternalError {
28            error: format!("{}", error),
29        }
30    }
31}
32
33impl From<bcs::Error> for Error {
34    fn from(error: bcs::Error) -> Self {
35        Self::SerializationError(format!("{}", error))
36    }
37}
38
39impl From<diem_secure_net::Error> for Error {
40    fn from(error: diem_secure_net::Error) -> Self {
41        Self::InternalError {
42            error: format!("{}", error),
43        }
44    }
45}