referrerpolicy=no-referrer-when-downgrade

sc_cli/
error.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Initialization errors.
20
21use std::path::PathBuf;
22
23use sp_core::crypto;
24
25/// Result type alias for the CLI.
26pub type Result<T> = std::result::Result<T, Error>;
27
28/// Error type for the CLI.
29#[derive(Debug, thiserror::Error)]
30#[allow(missing_docs)]
31pub enum Error {
32	#[error(transparent)]
33	Io(#[from] std::io::Error),
34
35	#[error(transparent)]
36	Cli(#[from] clap::Error),
37
38	#[error(transparent)]
39	Service(#[from] sc_service::Error),
40
41	#[error(transparent)]
42	Client(#[from] sp_blockchain::Error),
43
44	#[error(transparent)]
45	Codec(#[from] codec::Error),
46
47	#[error("Invalid input: {0}")]
48	Input(String),
49
50	#[error("Invalid listen multiaddress")]
51	InvalidListenMultiaddress,
52
53	#[error("Invalid URI; expecting either a secret URI or a public URI.")]
54	InvalidUri(crypto::PublicError),
55
56	#[error("Signature is an invalid format.")]
57	SignatureFormatInvalid,
58
59	#[error("Key is an invalid format.")]
60	KeyFormatInvalid,
61
62	#[error("Unknown key type, must be a known 4-character sequence")]
63	KeyTypeInvalid,
64
65	#[error("Signature verification failed")]
66	SignatureInvalid,
67
68	#[error("Key store operation failed")]
69	KeystoreOperation,
70
71	#[error("Key storage issue encountered")]
72	KeyStorage(#[from] sc_keystore::Error),
73
74	#[error("Invalid hexadecimal string data, {0:?}")]
75	HexDataConversion(array_bytes::Error),
76
77	/// Application specific error chain sequence forwarder.
78	#[error(transparent)]
79	Application(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
80
81	#[error(transparent)]
82	GlobalLoggerError(#[from] sc_tracing::logging::Error),
83
84	#[error(
85		"Starting an authorithy without network key in {0}.
86		\n This is not a safe operation because other authorities in the network may depend on your node having a stable identity.
87		\n Otherwise these other authorities may not being able to reach you.
88		\n If it is the first time running your node you could use one of the following methods:
89		\n 1. [Preferred] Separately generate the key with: <NODE_BINARY> key generate-node-key --base-path <YOUR_BASE_PATH>
90		\n 2. [Preferred] Separately generate the key with: <NODE_BINARY> key generate-node-key --file <YOUR_PATH_TO_NODE_KEY>
91		\n 3. [Preferred] Separately generate the key with: <NODE_BINARY> key generate-node-key --default-base-path
92		\n 4. [Unsafe] Pass --unsafe-force-node-key-generation and make sure you remove it for subsequent node restarts"
93	)]
94	NetworkKeyNotFound(PathBuf),
95	#[error("A network key already exists in path {0}")]
96	KeyAlreadyExistsInPath(PathBuf),
97}
98
99impl From<&str> for Error {
100	fn from(s: &str) -> Error {
101		Error::Input(s.to_string())
102	}
103}
104
105impl From<String> for Error {
106	fn from(s: String) -> Error {
107		Error::Input(s)
108	}
109}
110
111impl From<crypto::PublicError> for Error {
112	fn from(e: crypto::PublicError) -> Error {
113		Error::InvalidUri(e)
114	}
115}
116
117impl From<array_bytes::Error> for Error {
118	fn from(e: array_bytes::Error) -> Error {
119		Error::HexDataConversion(e)
120	}
121}