1use std::path::PathBuf;
10
11use subsoil::core::crypto;
12
13pub type Result<T> = std::result::Result<T, Error>;
15
16#[derive(Debug, thiserror::Error)]
18#[allow(missing_docs)]
19pub enum Error {
20 #[error(transparent)]
21 Io(#[from] std::io::Error),
22
23 #[error(transparent)]
24 Cli(#[from] clap::Error),
25
26 #[error(transparent)]
27 Service(#[from] soil_service::Error),
28
29 #[error(transparent)]
30 Client(#[from] soil_client::blockchain::Error),
31
32 #[error(transparent)]
33 Codec(#[from] codec::Error),
34
35 #[error("Invalid input: {0}")]
36 Input(String),
37
38 #[error("Invalid listen multiaddress")]
39 InvalidListenMultiaddress,
40
41 #[error("Invalid URI; expecting either a secret URI or a public URI.")]
42 InvalidUri(crypto::PublicError),
43
44 #[error("Signature is an invalid format.")]
45 SignatureFormatInvalid,
46
47 #[error("Key is an invalid format.")]
48 KeyFormatInvalid,
49
50 #[error("Unknown key type, must be a known 4-character sequence")]
51 KeyTypeInvalid,
52
53 #[error("Signature verification failed")]
54 SignatureInvalid,
55
56 #[error("Key store operation failed")]
57 KeystoreOperation,
58
59 #[error("Key storage issue encountered")]
60 KeyStorage(#[from] soil_client::keystore::Error),
61
62 #[error("Invalid hexadecimal string data, {0:?}")]
63 HexDataConversion(array_bytes::Error),
64
65 #[error(transparent)]
67 Application(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
68
69 #[error(transparent)]
70 GlobalLoggerError(#[from] soil_client::tracing::logging::Error),
71
72 #[error(
73 "Starting an authorithy without network key in {0}.
74 \n This is not a safe operation because other authorities in the network may depend on your node having a stable identity.
75 \n Otherwise these other authorities may not being able to reach you.
76 \n If it is the first time running your node you could use one of the following methods:
77 \n 1. [Preferred] Separately generate the key with: <NODE_BINARY> key generate-node-key --base-path <YOUR_BASE_PATH>
78 \n 2. [Preferred] Separately generate the key with: <NODE_BINARY> key generate-node-key --file <YOUR_PATH_TO_NODE_KEY>
79 \n 3. [Preferred] Separately generate the key with: <NODE_BINARY> key generate-node-key --default-base-path
80 \n 4. [Unsafe] Pass --unsafe-force-node-key-generation and make sure you remove it for subsequent node restarts"
81 )]
82 NetworkKeyNotFound(PathBuf),
83 #[error("A network key already exists in path {0}")]
84 KeyAlreadyExistsInPath(PathBuf),
85}
86
87impl From<&str> for Error {
88 fn from(s: &str) -> Error {
89 Error::Input(s.to_string())
90 }
91}
92
93impl From<String> for Error {
94 fn from(s: String) -> Error {
95 Error::Input(s)
96 }
97}
98
99impl From<crypto::PublicError> for Error {
100 fn from(e: crypto::PublicError) -> Error {
101 Error::InvalidUri(e)
102 }
103}
104
105impl From<array_bytes::Error> for Error {
106 fn from(e: array_bytes::Error) -> Error {
107 Error::HexDataConversion(e)
108 }
109}