Skip to content

Commit

Permalink
chore: rewrite all error messages for consistency (paradigmxyz#5176)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Krasiuk <[email protected]>
  • Loading branch information
DaniPopes and rkrasiuk authored Oct 25, 2023
1 parent 1c0373b commit e05dba6
Show file tree
Hide file tree
Showing 73 changed files with 642 additions and 592 deletions.
2 changes: 1 addition & 1 deletion bin/reth/src/args/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum SecretKeyError {
SecretKeyDecodeError(#[from] SecretKeyBaseError),
#[error(transparent)]
SecretKeyFsPathError(#[from] FsPathError),
#[error("Failed to access key file {secret_file:?}: {error}")]
#[error("failed to access key file {secret_file:?}: {error}")]
FailedToAccessKeyFile { error: io::Error, secret_file: PathBuf },
}

Expand Down
8 changes: 4 additions & 4 deletions bin/reth/src/args/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ pub fn hash_or_num_value_parser(value: &str) -> eyre::Result<BlockHashOrNumber,
#[derive(thiserror::Error, Debug)]
pub enum SocketAddressParsingError {
/// Failed to convert the string into a socket addr
#[error("Cannot parse socket address: {0}")]
#[error("could not parse socket address: {0}")]
Io(#[from] std::io::Error),
/// Input must not be empty
#[error("Cannot parse socket address from empty string")]
#[error("cannot parse socket address from empty string")]
Empty,
/// Failed to parse the address
#[error("Could not parse socket address from {0}")]
#[error("could not parse socket address from {0}")]
Parse(String),
/// Failed to parse port
#[error("Could not parse port: {0}")]
#[error("could not parse port: {0}")]
Port(#[from] std::num::ParseIntError),
}

Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tracing::debug;
pub enum InitDatabaseError {
/// An existing genesis block was found in the database, and its hash did not match the hash of
/// the chainspec.
#[error("Genesis hash in the database does not match the specified chainspec: chainspec is {chainspec_hash}, database is {database_hash}")]
#[error("genesis hash in the database does not match the specified chainspec: chainspec is {chainspec_hash}, database is {database_hash}")]
GenesisHashMismatch {
/// Expected genesis hash.
chainspec_hash: B256,
Expand Down
6 changes: 3 additions & 3 deletions crates/consensus/beacon/src/engine/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ pub type BeaconEngineResult<Ok> = Result<Ok, BeaconConsensusEngineError>;
#[derive(Debug, thiserror::Error)]
pub enum BeaconConsensusEngineError {
/// Pipeline channel closed.
#[error("Pipeline channel closed")]
#[error("pipeline channel closed")]
PipelineChannelClosed,
/// Pipeline error.
#[error(transparent)]
Pipeline(#[from] Box<PipelineError>),
/// Pruner channel closed.
#[error("Pruner channel closed")]
#[error("pruner channel closed")]
PrunerChannelClosed,
/// Hook error.
#[error(transparent)]
Expand Down Expand Up @@ -50,7 +50,7 @@ impl From<reth_interfaces::db::DatabaseError> for BeaconConsensusEngineError {
#[derive(Debug, thiserror::Error)]
pub enum BeaconForkChoiceUpdateError {
/// Thrown when a forkchoice update resulted in an error.
#[error("Forkchoice update error: {0}")]
#[error("forkchoice update error: {0}")]
ForkchoiceUpdateError(#[from] ForkchoiceUpdateError),
/// Internal errors, for example, error while reading from the database.
#[error(transparent)]
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/beacon/src/engine/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ pub enum EngineHookAction {}
#[derive(Debug, thiserror::Error)]
pub enum EngineHookError {
/// Hook channel closed.
#[error("Hook channel closed")]
#[error("hook channel closed")]
ChannelClosed,
/// Common error. Wrapper around [RethError].
#[error(transparent)]
Common(#[from] RethError),
/// An internal error occurred.
#[error("Internal hook error occurred.")]
#[error(transparent)]
Internal(#[from] Box<dyn std::error::Error + Send + Sync>),
}

Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ where
head_block.total_difficulty =
self.blockchain.header_td_by_number(head_block.number)?.ok_or_else(|| {
RethError::Provider(ProviderError::TotalDifficultyNotFound {
number: head_block.number,
block_number: head_block.number,
})
})?;
self.sync_state_updater.update_status(head_block);
Expand Down
28 changes: 14 additions & 14 deletions crates/interfaces/src/blockchain_tree/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@ use reth_primitives::{BlockHash, BlockNumber, SealedBlock};
#[allow(missing_docs)]
pub enum BlockchainTreeError {
/// Thrown if the block number is lower than the last finalized block number.
#[error("Block number is lower than the last finalized block number #{last_finalized}")]
#[error("block number is lower than the last finalized block number #{last_finalized}")]
PendingBlockIsFinalized {
/// The block number of the last finalized block.
last_finalized: BlockNumber,
},
/// Thrown if no side chain could be found for the block.
#[error("BlockChainId can't be found in BlockchainTree with internal index {chain_id}")]
#[error("blockChainId can't be found in BlockchainTree with internal index {chain_id}")]
BlockSideChainIdConsistency {
/// The internal identifier for the side chain.
chain_id: u64,
},
/// Thrown if a canonical chain header cannot be found.
#[error("Canonical chain header #{block_hash} can't be found ")]
#[error("canonical chain header {block_hash} can't be found")]
CanonicalChain {
/// The block hash of the missing canonical chain header.
block_hash: BlockHash,
},
/// Thrown if a block number cannot be found in the blockchain tree chain.
#[error("Block number #{block_number} not found in blockchain tree chain")]
#[error("block number #{block_number} not found in blockchain tree chain")]
BlockNumberNotFoundInChain {
/// The block number that could not be found.
block_number: BlockNumber,
},
/// Thrown if a block hash cannot be found in the blockchain tree chain.
#[error("Block hash {block_hash} not found in blockchain tree chain")]
#[error("block hash {block_hash} not found in blockchain tree chain")]
BlockHashNotFoundInChain {
/// The block hash that could not be found.
block_hash: BlockHash,
},
// Thrown if the block failed to buffer
#[error("Block with hash {block_hash:?} failed to buffer")]
#[error("block with hash {block_hash} failed to buffer")]
BlockBufferingFailed {
/// The block hash of the block that failed to buffer.
block_hash: BlockHash,
Expand All @@ -62,10 +62,10 @@ pub enum CanonicalError {
#[error(transparent)]
BlockchainTree(#[from] BlockchainTreeError),
/// Error indicating a transaction reverted during execution.
#[error("Transaction error on revert: {inner:?}")]
#[error("transaction error on revert: {inner}")]
CanonicalRevert { inner: String },
/// Error indicating a transaction failed to commit during execution.
#[error("Transaction error on commit: {inner:?}")]
#[error("transaction error on commit: {inner}")]
CanonicalCommit { inner: String },
}

Expand Down Expand Up @@ -190,23 +190,23 @@ impl InsertBlockErrorData {
#[derive(Debug, thiserror::Error)]
pub enum InsertBlockErrorKind {
/// Failed to recover senders for the block
#[error("Failed to recover senders for block")]
#[error("failed to recover senders for block")]
SenderRecovery,
/// Block violated consensus rules.
#[error(transparent)]
Consensus(ConsensusError),
Consensus(#[from] ConsensusError),
/// Block execution failed.
#[error(transparent)]
Execution(BlockExecutionError),
Execution(#[from] BlockExecutionError),
/// Block violated tree invariants.
#[error(transparent)]
Tree(#[from] BlockchainTreeError),
/// An internal error occurred, like interacting with the database.
#[error("Internal error")]
Internal(Box<dyn std::error::Error + Send + Sync>),
#[error(transparent)]
Internal(#[from] Box<dyn std::error::Error + Send + Sync>),
/// Canonical error.
#[error(transparent)]
Canonical(CanonicalError),
Canonical(#[from] CanonicalError),
/// BlockchainTree error.
#[error(transparent)]
BlockchainTree(BlockchainTreeError),
Expand Down
Loading

0 comments on commit e05dba6

Please sign in to comment.