mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 19:11:02 +00:00
use thiserror instead of derive_more for error handling (#10696)
* use thiserror instead of derive_more for error handling Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Update utils/prometheus/src/lib.rs * Update utils/prometheus/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -13,9 +13,8 @@ readme = "README.md"
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
derive_more = "0.99.16"
|
||||
thiserror = "1.0"
|
||||
dyn-clone = "1.0"
|
||||
fork-tree = { version = "3.0.0", path = "../../utils/fork-tree" }
|
||||
futures = "0.3.9"
|
||||
|
||||
@@ -23,7 +23,7 @@ futures = "0.3.16"
|
||||
serde = { version = "1.0.105", features = ["derive"] }
|
||||
serde_json = "1.0.50"
|
||||
log = "0.4.8"
|
||||
derive_more = "0.99.2"
|
||||
thiserror = "1.0"
|
||||
parity-scale-codec = { version = "2.0.0", features = ["derive"] }
|
||||
sc-client-api = { version = "4.0.0-dev", path = "../../api" }
|
||||
|
||||
|
||||
@@ -16,21 +16,21 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#[derive(derive_more::Display, derive_more::From)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
/// Top-level error type for the RPC handler
|
||||
pub enum Error {
|
||||
/// The GRANDPA RPC endpoint is not ready.
|
||||
#[display(fmt = "GRANDPA RPC endpoint not ready")]
|
||||
#[error("GRANDPA RPC endpoint not ready")]
|
||||
EndpointNotReady,
|
||||
/// GRANDPA reports the authority set id to be larger than 32-bits.
|
||||
#[display(fmt = "GRANDPA reports authority set id unreasonably large")]
|
||||
#[error("GRANDPA reports authority set id unreasonably large")]
|
||||
AuthoritySetIdReportedAsUnreasonablyLarge,
|
||||
/// GRANDPA reports voter state with round id or weights larger than 32-bits.
|
||||
#[display(fmt = "GRANDPA reports voter state as unreasonably large")]
|
||||
#[error("GRANDPA reports voter state as unreasonably large")]
|
||||
VoterStateReportsUnreasonablyLargeNumbers,
|
||||
/// GRANDPA prove finality failed.
|
||||
#[display(fmt = "GRANDPA prove finality rpc failed: {}", _0)]
|
||||
ProveFinalityFailed(sc_finality_grandpa::FinalityProofError),
|
||||
#[error("GRANDPA prove finality rpc failed: {0}")]
|
||||
ProveFinalityFailed(#[from] sc_finality_grandpa::FinalityProofError),
|
||||
}
|
||||
|
||||
/// The error codes returned by jsonrpc.
|
||||
|
||||
@@ -32,23 +32,22 @@ use sp_finality_grandpa::{AuthorityId, AuthorityList};
|
||||
use crate::SetId;
|
||||
|
||||
/// Error type returned on operations on the `AuthoritySet`.
|
||||
#[derive(Debug, derive_more::Display)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error<N, E> {
|
||||
#[display(fmt = "Invalid authority set, either empty or with an authority weight set to 0.")]
|
||||
#[error("Invalid authority set, either empty or with an authority weight set to 0.")]
|
||||
InvalidAuthoritySet,
|
||||
#[display(fmt = "Client error during ancestry lookup: {}", _0)]
|
||||
#[error("Client error during ancestry lookup: {0}")]
|
||||
Client(E),
|
||||
#[display(fmt = "Duplicate authority set change.")]
|
||||
#[error("Duplicate authority set change.")]
|
||||
DuplicateAuthoritySetChange,
|
||||
#[display(fmt = "Multiple pending forced authority set changes are not allowed.")]
|
||||
#[error("Multiple pending forced authority set changes are not allowed.")]
|
||||
MultiplePendingForcedAuthoritySetChanges,
|
||||
#[display(
|
||||
fmt = "A pending forced authority set change could not be applied since it must be applied \
|
||||
after the pending standard change at #{}",
|
||||
_0
|
||||
#[error(
|
||||
"A pending forced authority set change could not be applied since it must be applied \
|
||||
after the pending standard change at #{0}"
|
||||
)]
|
||||
ForcedAuthoritySetChangeDependencyUnsatisfied(N),
|
||||
#[display(fmt = "Invalid operation in the pending changes tree: {}", _0)]
|
||||
#[error("Invalid operation in the pending changes tree: {0}")]
|
||||
ForkTree(fork_tree::Error<E>),
|
||||
}
|
||||
|
||||
|
||||
@@ -132,17 +132,18 @@ pub struct FinalityProof<Header: HeaderT> {
|
||||
}
|
||||
|
||||
/// Errors occurring when trying to prove finality
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum FinalityProofError {
|
||||
/// The requested block has not yet been finalized.
|
||||
#[display(fmt = "Block not yet finalized")]
|
||||
#[error("Block not yet finalized")]
|
||||
BlockNotYetFinalized,
|
||||
/// The requested block is not covered by authority set changes. Likely this means the block is
|
||||
/// in the latest authority set, and the subscription API is more appropriate.
|
||||
#[display(fmt = "Block not covered by authority set changes")]
|
||||
#[error("Block not covered by authority set changes")]
|
||||
BlockNotInAuthoritySetChanges,
|
||||
/// Errors originating from the client.
|
||||
Client(sp_blockchain::Error),
|
||||
#[error(transparent)]
|
||||
Client(#[from] sp_blockchain::Error),
|
||||
}
|
||||
|
||||
fn prove_finality<Block, B>(
|
||||
|
||||
@@ -34,26 +34,25 @@ use sp_runtime::{
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
/// Warp proof processing error.
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// Decoding error.
|
||||
#[display(fmt = "Failed to decode block hash: {}.", _0)]
|
||||
DecodeScale(codec::Error),
|
||||
#[error("Failed to decode block hash: {0}.")]
|
||||
DecodeScale(#[from] codec::Error),
|
||||
/// Client backend error.
|
||||
Client(sp_blockchain::Error),
|
||||
#[error("{0}")]
|
||||
Client(#[from] sp_blockchain::Error),
|
||||
/// Invalid request data.
|
||||
#[from(ignore)]
|
||||
#[error("{0}")]
|
||||
InvalidRequest(String),
|
||||
/// Invalid warp proof.
|
||||
#[from(ignore)]
|
||||
#[error("{0}")]
|
||||
InvalidProof(String),
|
||||
/// Missing header or authority set change data.
|
||||
#[display(fmt = "Missing required data to be able to answer request.")]
|
||||
#[error("Missing required data to be able to answer request.")]
|
||||
MissingData,
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
/// The maximum size in bytes of the `WarpSyncProof`.
|
||||
pub(super) const MAX_WARP_SYNC_PROOF_SIZE: usize = 8 * 1024 * 1024;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user