gadget_sdk/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use alloc::string::String;
use sp_core::ecdsa;
use thiserror::Error;

/// Represents errors that can occur in the SDK.
#[derive(Debug, Error)]
pub enum Error {
    #[error("Client error: {0}")]
    Client(String),

    #[error("Job error: {reason}")]
    Job { reason: String },

    #[error("Network error: {reason}")]
    Network { reason: String },

    #[error("Storage error: {reason}")]
    Store { reason: String },

    #[error("Keystore error: {0}")]
    Keystore(#[from] crate::keystore::error::Error),

    #[error("Config error: {0}")]
    Config(#[from] crate::config::Error),

    #[error("Job runner error: {0}")]
    Runner(#[from] crate::runners::RunnerError),

    #[error("Executor error: {0}")]
    Executor(#[from] crate::executor::process::Error),

    #[error("Docker error: {0}")]
    Docker(#[from] crate::docker::Error),

    #[error("Missing network ID")]
    MissingNetworkId,

    #[error("Peer not found: {id:?}")]
    PeerNotFound { id: ecdsa::Public },

    #[cfg(feature = "std")]
    #[error("Join error: {0}")]
    Join(#[from] tokio::task::JoinError),

    // TODO: Add feature flag for substrate/tangle
    #[error("Subxt error: {0}")]
    #[cfg(any(feature = "std", feature = "wasm"))]
    Subxt(#[from] subxt::Error),

    #[error("{0}")]
    Json(#[from] serde_json::Error),

    #[error("{0}")]
    BlueprintSerde(#[from] blueprint_serde::error::Error),

    #[cfg(feature = "std")]
    #[error("Prometheus error: {err}")]
    Prometheus { err: String },

    #[cfg(feature = "std")]
    #[error("Metrics error: {0}")]
    Metrics(#[from] crate::metrics::Error),

    #[error("Io error: {0}")]
    IoError(#[from] std::io::Error),

    #[error("The type has been skipped in the preprocessor")]
    SkipPreProcessedType,

    #[error("Bad argument decoding for {0}")]
    BadArgumentDecoding(String),

    #[error("Color Eyre error: {0}")]
    Generic(#[from] color_eyre::Report),

    #[error("Other error: {0}")]
    Other(String),
}

impl From<bollard::errors::Error> for Error {
    fn from(error: bollard::errors::Error) -> Self {
        Error::Docker(crate::docker::Error::from(error))
    }
}

impl From<String> for Error {
    fn from(s: String) -> Self {
        Error::Other(s)
    }
}