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
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::job_runner::Error),

    #[error("Docker error: {0}")]
    Docker(#[from] bollard::errors::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),

    #[cfg(feature = "std")]
    #[error("Events watcher error: {0}")]
    EventsWatcher(#[from] crate::events_watcher::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("Other error: {0}")]
    Other(String),
}

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