From a70b1b9c6c1e68ff89e2850e701ebf171bc36169 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 27 Jul 2023 11:10:22 +1000 Subject: [PATCH] Use standard set of derives on all error types As part of an ongoing effort to make our error types stable and useful add a stand set of derives to all error types in the library. `#[derive(Debug, Clone, PartialEq, Eq)]` Add `Copy` if possible and the error type does not include `#[non_exhaustive]`. If an error type includes `io::Error` it only gets `#[derive(Debug)]`. --- bitcoin/src/address.rs | 2 +- bitcoin/src/base58.rs | 2 +- bitcoin/src/bip152.rs | 4 ++-- bitcoin/src/bip32.rs | 2 +- bitcoin/src/blockdata/block.rs | 2 +- bitcoin/src/blockdata/locktime/absolute.rs | 4 ++-- bitcoin/src/blockdata/locktime/relative.rs | 2 +- bitcoin/src/blockdata/script/mod.rs | 2 +- bitcoin/src/blockdata/script/push_bytes.rs | 4 ++-- bitcoin/src/blockdata/transaction.rs | 2 +- bitcoin/src/consensus/serde.rs | 4 ++-- bitcoin/src/crypto/ecdsa.rs | 2 +- bitcoin/src/crypto/key.rs | 2 +- bitcoin/src/crypto/sighash.rs | 4 ++-- bitcoin/src/crypto/taproot.rs | 2 +- bitcoin/src/merkle_tree/block.rs | 2 +- bitcoin/src/network/constants.rs | 2 +- bitcoin/src/network/message.rs | 2 +- bitcoin/src/parse.rs | 2 +- bitcoin/src/pow.rs | 2 +- bitcoin/src/psbt/mod.rs | 8 ++++---- bitcoin/src/sign_message.rs | 2 +- bitcoin/src/string.rs | 2 +- bitcoin/src/taproot.rs | 4 ++-- 24 files changed, 33 insertions(+), 33 deletions(-) diff --git a/bitcoin/src/address.rs b/bitcoin/src/address.rs index 28ef44a4..afa42dea 100644 --- a/bitcoin/src/address.rs +++ b/bitcoin/src/address.rs @@ -51,7 +51,7 @@ use crate::prelude::*; use crate::taproot::TapNodeHash; /// Address error. -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum Error { /// Base58 encoding error. diff --git a/bitcoin/src/base58.rs b/bitcoin/src/base58.rs index 98fea7cf..c35a40f7 100644 --- a/bitcoin/src/base58.rs +++ b/bitcoin/src/base58.rs @@ -217,7 +217,7 @@ impl SmallVec { } /// An error that might occur during base58 decoding. -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum Error { /// Invalid character encountered. diff --git a/bitcoin/src/bip152.rs b/bitcoin/src/bip152.rs index b04f352e..17c296c0 100644 --- a/bitcoin/src/bip152.rs +++ b/bitcoin/src/bip152.rs @@ -19,7 +19,7 @@ use crate::prelude::*; use crate::{block, io, Block, BlockHash, Transaction}; /// A BIP-152 error -#[derive(Clone, PartialEq, Eq, Debug, Copy, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum Error { /// An unknown version number was used. @@ -318,7 +318,7 @@ impl Decodable for BlockTransactionsRequest { /// A transaction index is requested that is out of range from the /// corresponding block. -#[derive(Clone, PartialEq, Eq, Debug, Copy, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct TxIndexOutOfRangeError(u64); impl fmt::Display for TxIndexOutOfRangeError { diff --git a/bitcoin/src/bip32.rs b/bitcoin/src/bip32.rs index 036b56af..a1513a72 100644 --- a/bitcoin/src/bip32.rs +++ b/bitcoin/src/bip32.rs @@ -448,7 +448,7 @@ impl fmt::Debug for DerivationPath { pub type KeySource = (Fingerprint, DerivationPath); /// A BIP32 error -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum Error { /// A pk->pk derivation was attempted on a hardened key diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs index 921565e6..967e8682 100644 --- a/bitcoin/src/blockdata/block.rs +++ b/bitcoin/src/blockdata/block.rs @@ -391,7 +391,7 @@ impl std::error::Error for Bip34Error { } /// A block validation error. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum ValidationError { /// The header hash is not below the target. BadProofOfWork, diff --git a/bitcoin/src/blockdata/locktime/absolute.rs b/bitcoin/src/blockdata/locktime/absolute.rs index 95e31242..b44e504c 100644 --- a/bitcoin/src/blockdata/locktime/absolute.rs +++ b/bitcoin/src/blockdata/locktime/absolute.rs @@ -600,7 +600,7 @@ impl From for Error { } /// An error that occurs when converting a `u32` to a lock time variant. -#[derive(Debug, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct ConversionError { /// The expected timelock unit, height (blocks) or time (seconds). unit: LockTimeUnit, @@ -646,7 +646,7 @@ impl fmt::Display for LockTimeUnit { } /// Errors than occur when operating on lock times. -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum OperationError { /// Cannot compare different lock time units (height vs time). diff --git a/bitcoin/src/blockdata/locktime/relative.rs b/bitcoin/src/blockdata/locktime/relative.rs index d2bdfa97..a61117c1 100644 --- a/bitcoin/src/blockdata/locktime/relative.rs +++ b/bitcoin/src/blockdata/locktime/relative.rs @@ -298,7 +298,7 @@ impl fmt::Display for Time { } /// Errors related to relative lock times. -#[derive(Clone, PartialEq, Eq, Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum Error { /// Input time in seconds was too large to be encoded to a 16 bit 512 second interval. diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs index 640e7226..ee45ed45 100644 --- a/bitcoin/src/blockdata/script/mod.rs +++ b/bitcoin/src/blockdata/script/mod.rs @@ -670,7 +670,7 @@ pub(super) fn bytes_to_asm_fmt(script: &[u8], f: &mut dyn fmt::Write) -> fmt::Re /// Ways that a script might fail. Not everything is split up as /// much as it could be; patches welcome if more detailed errors /// would help you. -#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum Error { /// Something did a non-minimal push; for more information see diff --git a/bitcoin/src/blockdata/script/push_bytes.rs b/bitcoin/src/blockdata/script/push_bytes.rs index ae14013b..c1c184a2 100644 --- a/bitcoin/src/blockdata/script/push_bytes.rs +++ b/bitcoin/src/blockdata/script/push_bytes.rs @@ -369,7 +369,7 @@ mod error { /// Error returned on attempt to create too large `PushBytes`. #[allow(unused)] - #[derive(Debug, Clone)] + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct PushBytesError { never: core::convert::Infallible, } @@ -391,7 +391,7 @@ mod error { use core::fmt; /// Error returned on attempt to create too large `PushBytes`. - #[derive(Debug, Clone)] + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct PushBytesError { /// How long the input was. pub(super) len: usize, diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index 52d06c38..edd0c223 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -91,7 +91,7 @@ impl fmt::Display for OutPoint { } /// An error in parsing an OutPoint. -#[derive(Clone, PartialEq, Eq, Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum ParseOutPointError { /// Error in TXID part. diff --git a/bitcoin/src/consensus/serde.rs b/bitcoin/src/consensus/serde.rs index 2b857547..62c17469 100644 --- a/bitcoin/src/consensus/serde.rs +++ b/bitcoin/src/consensus/serde.rs @@ -101,11 +101,11 @@ pub mod hex { // TODO: statically prove impossible cases /// Error returned when a hex string decoder can't be created. - #[derive(Debug)] + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct DecodeInitError(hex::HexToBytesError); /// Error returned when a hex string contains invalid characters. - #[derive(Debug)] + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct DecodeError(hex::HexToBytesError); /// Hex decoder state. diff --git a/bitcoin/src/crypto/ecdsa.rs b/bitcoin/src/crypto/ecdsa.rs index 7f0e6d15..8f295518 100644 --- a/bitcoin/src/crypto/ecdsa.rs +++ b/bitcoin/src/crypto/ecdsa.rs @@ -184,7 +184,7 @@ impl<'a> IntoIterator for &'a SerializedSignature { } /// A key-related error. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum Error { /// Hex decoding error diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs index 8471af53..e870592c 100644 --- a/bitcoin/src/crypto/key.rs +++ b/bitcoin/src/crypto/key.rs @@ -24,7 +24,7 @@ use crate::taproot::{TapNodeHash, TapTweakHash}; use crate::{base58, io}; /// A key-related error. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum Error { /// Base58 encoding error diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs index 93c00da9..ec4a2ad7 100644 --- a/bitcoin/src/crypto/sighash.rs +++ b/bitcoin/src/crypto/sighash.rs @@ -199,7 +199,7 @@ impl str::FromStr for TapSighashType { } /// Possible errors in computing the signature message. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum Error { /// Could happen only by using `*_encode_signing_*` methods with custom writers, engines writers @@ -531,7 +531,7 @@ impl_std_error!(NonStandardSighashType); /// Error returned for failure during parsing one of the sighash types. /// /// This is currently returned for unrecognized sighash strings. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct SighashTypeParseError { /// The unrecognized string we attempted to parse. pub unrecognized: String, diff --git a/bitcoin/src/crypto/taproot.rs b/bitcoin/src/crypto/taproot.rs index 9a15cce1..e6f20832 100644 --- a/bitcoin/src/crypto/taproot.rs +++ b/bitcoin/src/crypto/taproot.rs @@ -60,7 +60,7 @@ impl Signature { /// An error constructing a [`taproot::Signature`] from a byte slice. /// /// [`taproot::Signature`]: crate::crypto::taproot::Signature -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum SigFromSliceError { /// Invalid signature hash type. diff --git a/bitcoin/src/merkle_tree/block.rs b/bitcoin/src/merkle_tree/block.rs index 1a45eb1e..0ca966f0 100644 --- a/bitcoin/src/merkle_tree/block.rs +++ b/bitcoin/src/merkle_tree/block.rs @@ -457,7 +457,7 @@ impl Decodable for PartialMerkleTree { } /// An error when verifying the merkle block. -#[derive(Clone, PartialEq, Eq, Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum MerkleBlockError { /// Merkle root in the header doesn't match to the root calculated from partial merkle tree. diff --git a/bitcoin/src/network/constants.rs b/bitcoin/src/network/constants.rs index 882592a2..1b4d172f 100644 --- a/bitcoin/src/network/constants.rs +++ b/bitcoin/src/network/constants.rs @@ -310,7 +310,7 @@ impl Magic { } /// An error in parsing magic bytes. -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct ParseMagicError { /// The error that occurred when parsing the string. error: hex::HexToArrayError, diff --git a/bitcoin/src/network/message.rs b/bitcoin/src/network/message.rs index a98119ff..75d22de6 100644 --- a/bitcoin/src/network/message.rs +++ b/bitcoin/src/network/message.rs @@ -128,7 +128,7 @@ impl Decodable for CommandString { /// Error returned when a command string is invalid. /// /// This is currently returned for command strings longer than 12. -#[derive(Clone, Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct CommandStringError { cow: Cow<'static, str>, } diff --git a/bitcoin/src/parse.rs b/bitcoin/src/parse.rs index 777a5038..3e04f5ae 100644 --- a/bitcoin/src/parse.rs +++ b/bitcoin/src/parse.rs @@ -18,7 +18,7 @@ use crate::prelude::*; /// Note that this is larger than the type from `core` so if it's passed through a deep call stack /// in a performance-critical application you may want to box it or throw away the context by /// converting to `core` type. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct ParseIntError { input: String, // for displaying - see Display impl with nice error message below diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index 2e647909..e49348c5 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -707,7 +707,7 @@ impl> From for U256 { } /// Error from `TryFrom` implementations, occurs when input is negative. -#[derive(Debug)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct TryFromError(i128); impl fmt::Display for TryFromError { diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs index 7c8df637..dfad6f98 100644 --- a/bitcoin/src/psbt/mod.rs +++ b/bitcoin/src/psbt/mod.rs @@ -575,7 +575,7 @@ impl_get_key_for_map!(BTreeMap); impl_get_key_for_map!(HashMap); /// Errors when getting a key. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum GetKeyError { /// A bip32 error. @@ -658,7 +658,7 @@ pub enum SigningAlgorithm { } /// Errors encountered while calculating the sighash message. -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum SignError { /// Input index out of bounds (actual index, maximum index allowed). @@ -696,7 +696,7 @@ impl fmt::Display for SignError { use self::SignError::*; match *self { - IndexOutOfBounds(ind, len) => { + IndexOutOfBounds(ref ind, ref len) => { write!(f, "index {}, psbt input len: {}", ind, len) } InvalidSighashType => write!(f, "invalid sighash type"), @@ -707,7 +707,7 @@ impl fmt::Display for SignError { MismatchedAlgoKey => write!(f, "signing algorithm and key type does not match"), NotEcdsa => write!(f, "attempted to ECDSA sign an non-ECDSA input"), NotWpkh => write!(f, "the scriptPubkey is not a P2WPKH script"), - SighashComputation(e) => write!(f, "sighash: {}", e), + SighashComputation(ref e) => write!(f, "sighash: {}", e), UnknownOutputType => write!(f, "unable to determine the output type"), KeyNotFound => write!(f, "unable to find key"), WrongSigningAlgorithm => diff --git a/bitcoin/src/sign_message.rs b/bitcoin/src/sign_message.rs index 94b0658f..d4a4a6da 100644 --- a/bitcoin/src/sign_message.rs +++ b/bitcoin/src/sign_message.rs @@ -30,7 +30,7 @@ mod message_signing { use crate::prelude::*; /// An error used for dealing with Bitcoin Signed Messages. - #[derive(Debug, PartialEq, Eq)] + #[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum MessageSignatureError { /// Signature is expected to be 65 bytes. diff --git a/bitcoin/src/string.rs b/bitcoin/src/string.rs index 1afbeea4..fd28e7c3 100644 --- a/bitcoin/src/string.rs +++ b/bitcoin/src/string.rs @@ -35,7 +35,7 @@ pub trait FromHexStr: Sized { } /// Hex parsing error -#[derive(Debug, Eq, PartialEq, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum FromHexError { /// The input was not a valid hex string, contains the error that occurred while parsing. ParseHex(E), diff --git a/bitcoin/src/taproot.rs b/bitcoin/src/taproot.rs index 9a90757f..3a19d986 100644 --- a/bitcoin/src/taproot.rs +++ b/bitcoin/src/taproot.rs @@ -1435,7 +1435,7 @@ impl<'de> serde::Deserialize<'de> for LeafVersion { } /// Detailed error type for taproot builder. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum TaprootBuilderError { /// Merkle tree depth must not be more than 128. @@ -1491,7 +1491,7 @@ impl std::error::Error for TaprootBuilderError { } /// Detailed error type for taproot utilities. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum TaprootError { /// Proof size must be a multiple of 32.