1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Tanssi is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>
16

            
17
#[derive(thiserror::Error, Debug)]
18
pub enum Error {
19
    #[error(transparent)]
20
    PolkadotService(#[from] polkadot_service::Error),
21

            
22
    #[error(transparent)]
23
    SubstrateCli(#[from] sc_cli::Error),
24

            
25
    #[error(transparent)]
26
    SubstrateService(#[from] sc_service::Error),
27

            
28
    #[error(transparent)]
29
    SubstrateTracing(#[from] sc_tracing::logging::Error),
30

            
31
    #[cfg(not(feature = "pyroscope"))]
32
    #[error("Binary was not compiled with `--feature=pyroscope`")]
33
    PyroscopeNotCompiledIn,
34

            
35
    #[cfg(feature = "pyroscope")]
36
    #[error("Failed to connect to pyroscope agent")]
37
    PyroscopeError(#[from] pyro::error::PyroscopeError),
38

            
39
    #[error("Failed to resolve provided URL")]
40
    AddressResolutionFailure(#[from] std::io::Error),
41

            
42
    #[error("URL did not resolve to anything")]
43
    AddressResolutionMissing,
44

            
45
    #[error("Command is not implemented")]
46
    CommandNotImplemented,
47

            
48
    #[error(transparent)]
49
    Storage(#[from] sc_storage_monitor::Error),
50

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

            
54
    #[error("This subcommand is only available when compiled with `{feature}`")]
55
    FeatureNotEnabled { feature: &'static str },
56
}
57

            
58
impl From<String> for Error {
59
    fn from(s: String) -> Self {
60
        Self::Other(s)
61
    }
62
}