Merge rust-bitcoin/rust-bitcoin#1963: Use standard set of error derives where possible
a70b1b9c6c
Use standard set of derives on all error types (Tobin C. Harding)2867acfffa
Add non_exhaustive to SignError (Tobin C. Harding) Pull request description: This is a redo of #1961 without changing `io::Error` to `io::ErrorKind` and just leaving errors with an IO error in them with only `#[derive(Debug)]`. ACKs for top commit: apoelstra: ACKa70b1b9c6c
sanket1729: utACKa70b1b9c6c
. Tree-SHA512: 4a716077ed7e852d40b649d03239dea80039b5f32d30b8c572a5c3cd8e0ffbfe2593f8e5b18855fb4e659d08eefb515a6508e138fd0b14e82ab225876653d056
This commit is contained in:
commit
b73a0ada92
|
@ -51,7 +51,7 @@ use crate::prelude::*;
|
||||||
use crate::taproot::TapNodeHash;
|
use crate::taproot::TapNodeHash;
|
||||||
|
|
||||||
/// Address error.
|
/// Address error.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Base58 encoding error.
|
/// Base58 encoding error.
|
||||||
|
|
|
@ -217,7 +217,7 @@ impl<T: Default + Copy> SmallVec<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error that might occur during base58 decoding.
|
/// An error that might occur during base58 decoding.
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Invalid character encountered.
|
/// Invalid character encountered.
|
||||||
|
|
|
@ -19,7 +19,7 @@ use crate::prelude::*;
|
||||||
use crate::{block, io, Block, BlockHash, Transaction};
|
use crate::{block, io, Block, BlockHash, Transaction};
|
||||||
|
|
||||||
/// A BIP-152 error
|
/// A BIP-152 error
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Copy, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// An unknown version number was used.
|
/// 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
|
/// A transaction index is requested that is out of range from the
|
||||||
/// corresponding block.
|
/// corresponding block.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Copy, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct TxIndexOutOfRangeError(u64);
|
pub struct TxIndexOutOfRangeError(u64);
|
||||||
|
|
||||||
impl fmt::Display for TxIndexOutOfRangeError {
|
impl fmt::Display for TxIndexOutOfRangeError {
|
||||||
|
|
|
@ -448,7 +448,7 @@ impl fmt::Debug for DerivationPath {
|
||||||
pub type KeySource = (Fingerprint, DerivationPath);
|
pub type KeySource = (Fingerprint, DerivationPath);
|
||||||
|
|
||||||
/// A BIP32 error
|
/// A BIP32 error
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// A pk->pk derivation was attempted on a hardened key
|
/// A pk->pk derivation was attempted on a hardened key
|
||||||
|
|
|
@ -391,7 +391,7 @@ impl std::error::Error for Bip34Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A block validation error.
|
/// A block validation error.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum ValidationError {
|
pub enum ValidationError {
|
||||||
/// The header hash is not below the target.
|
/// The header hash is not below the target.
|
||||||
BadProofOfWork,
|
BadProofOfWork,
|
||||||
|
|
|
@ -600,7 +600,7 @@ impl From<ParseIntError> for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error that occurs when converting a `u32` to a lock time variant.
|
/// 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 {
|
pub struct ConversionError {
|
||||||
/// The expected timelock unit, height (blocks) or time (seconds).
|
/// The expected timelock unit, height (blocks) or time (seconds).
|
||||||
unit: LockTimeUnit,
|
unit: LockTimeUnit,
|
||||||
|
@ -646,7 +646,7 @@ impl fmt::Display for LockTimeUnit {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Errors than occur when operating on lock times.
|
/// Errors than occur when operating on lock times.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum OperationError {
|
pub enum OperationError {
|
||||||
/// Cannot compare different lock time units (height vs time).
|
/// Cannot compare different lock time units (height vs time).
|
||||||
|
|
|
@ -298,7 +298,7 @@ impl fmt::Display for Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Errors related to relative lock times.
|
/// Errors related to relative lock times.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Input time in seconds was too large to be encoded to a 16 bit 512 second interval.
|
/// Input time in seconds was too large to be encoded to a 16 bit 512 second interval.
|
||||||
|
|
|
@ -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
|
/// Ways that a script might fail. Not everything is split up as
|
||||||
/// much as it could be; patches welcome if more detailed errors
|
/// much as it could be; patches welcome if more detailed errors
|
||||||
/// would help you.
|
/// would help you.
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Something did a non-minimal push; for more information see
|
/// Something did a non-minimal push; for more information see
|
||||||
|
|
|
@ -369,7 +369,7 @@ mod error {
|
||||||
|
|
||||||
/// Error returned on attempt to create too large `PushBytes`.
|
/// Error returned on attempt to create too large `PushBytes`.
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct PushBytesError {
|
pub struct PushBytesError {
|
||||||
never: core::convert::Infallible,
|
never: core::convert::Infallible,
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,7 @@ mod error {
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
/// Error returned on attempt to create too large `PushBytes`.
|
/// Error returned on attempt to create too large `PushBytes`.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct PushBytesError {
|
pub struct PushBytesError {
|
||||||
/// How long the input was.
|
/// How long the input was.
|
||||||
pub(super) len: usize,
|
pub(super) len: usize,
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl fmt::Display for OutPoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error in parsing an OutPoint.
|
/// An error in parsing an OutPoint.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum ParseOutPointError {
|
pub enum ParseOutPointError {
|
||||||
/// Error in TXID part.
|
/// Error in TXID part.
|
||||||
|
|
|
@ -101,11 +101,11 @@ pub mod hex {
|
||||||
// TODO: statically prove impossible cases
|
// TODO: statically prove impossible cases
|
||||||
|
|
||||||
/// Error returned when a hex string decoder can't be created.
|
/// Error returned when a hex string decoder can't be created.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct DecodeInitError(hex::HexToBytesError);
|
pub struct DecodeInitError(hex::HexToBytesError);
|
||||||
|
|
||||||
/// Error returned when a hex string contains invalid characters.
|
/// Error returned when a hex string contains invalid characters.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct DecodeError(hex::HexToBytesError);
|
pub struct DecodeError(hex::HexToBytesError);
|
||||||
|
|
||||||
/// Hex decoder state.
|
/// Hex decoder state.
|
||||||
|
|
|
@ -184,7 +184,7 @@ impl<'a> IntoIterator for &'a SerializedSignature {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A key-related error.
|
/// A key-related error.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Hex decoding error
|
/// Hex decoding error
|
||||||
|
|
|
@ -24,7 +24,7 @@ use crate::taproot::{TapNodeHash, TapTweakHash};
|
||||||
use crate::{base58, io};
|
use crate::{base58, io};
|
||||||
|
|
||||||
/// A key-related error.
|
/// A key-related error.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Base58 encoding error
|
/// Base58 encoding error
|
||||||
|
|
|
@ -199,7 +199,7 @@ impl str::FromStr for TapSighashType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Possible errors in computing the signature message.
|
/// Possible errors in computing the signature message.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Could happen only by using `*_encode_signing_*` methods with custom writers, engines writers
|
/// 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.
|
/// Error returned for failure during parsing one of the sighash types.
|
||||||
///
|
///
|
||||||
/// This is currently returned for unrecognized sighash strings.
|
/// This is currently returned for unrecognized sighash strings.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct SighashTypeParseError {
|
pub struct SighashTypeParseError {
|
||||||
/// The unrecognized string we attempted to parse.
|
/// The unrecognized string we attempted to parse.
|
||||||
pub unrecognized: String,
|
pub unrecognized: String,
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl Signature {
|
||||||
/// An error constructing a [`taproot::Signature`] from a byte slice.
|
/// An error constructing a [`taproot::Signature`] from a byte slice.
|
||||||
///
|
///
|
||||||
/// [`taproot::Signature`]: crate::crypto::taproot::Signature
|
/// [`taproot::Signature`]: crate::crypto::taproot::Signature
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum SigFromSliceError {
|
pub enum SigFromSliceError {
|
||||||
/// Invalid signature hash type.
|
/// Invalid signature hash type.
|
||||||
|
|
|
@ -457,7 +457,7 @@ impl Decodable for PartialMerkleTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error when verifying the merkle block.
|
/// An error when verifying the merkle block.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum MerkleBlockError {
|
pub enum MerkleBlockError {
|
||||||
/// Merkle root in the header doesn't match to the root calculated from partial merkle tree.
|
/// Merkle root in the header doesn't match to the root calculated from partial merkle tree.
|
||||||
|
|
|
@ -310,7 +310,7 @@ impl Magic {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error in parsing magic bytes.
|
/// An error in parsing magic bytes.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ParseMagicError {
|
pub struct ParseMagicError {
|
||||||
/// The error that occurred when parsing the string.
|
/// The error that occurred when parsing the string.
|
||||||
error: hex::HexToArrayError,
|
error: hex::HexToArrayError,
|
||||||
|
|
|
@ -128,7 +128,7 @@ impl Decodable for CommandString {
|
||||||
/// Error returned when a command string is invalid.
|
/// Error returned when a command string is invalid.
|
||||||
///
|
///
|
||||||
/// This is currently returned for command strings longer than 12.
|
/// This is currently returned for command strings longer than 12.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct CommandStringError {
|
pub struct CommandStringError {
|
||||||
cow: Cow<'static, str>,
|
cow: Cow<'static, str>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
/// 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
|
/// in a performance-critical application you may want to box it or throw away the context by
|
||||||
/// converting to `core` type.
|
/// converting to `core` type.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ParseIntError {
|
pub struct ParseIntError {
|
||||||
input: String,
|
input: String,
|
||||||
// for displaying - see Display impl with nice error message below
|
// for displaying - see Display impl with nice error message below
|
||||||
|
|
|
@ -707,7 +707,7 @@ impl<T: Into<u128>> From<T> for U256 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Error from `TryFrom<signed type>` implementations, occurs when input is negative.
|
/// Error from `TryFrom<signed type>` implementations, occurs when input is negative.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct TryFromError(i128);
|
pub struct TryFromError(i128);
|
||||||
|
|
||||||
impl fmt::Display for TryFromError {
|
impl fmt::Display for TryFromError {
|
||||||
|
|
|
@ -575,7 +575,7 @@ impl_get_key_for_map!(BTreeMap);
|
||||||
impl_get_key_for_map!(HashMap);
|
impl_get_key_for_map!(HashMap);
|
||||||
|
|
||||||
/// Errors when getting a key.
|
/// Errors when getting a key.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum GetKeyError {
|
pub enum GetKeyError {
|
||||||
/// A bip32 error.
|
/// A bip32 error.
|
||||||
|
@ -658,7 +658,8 @@ pub enum SigningAlgorithm {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Errors encountered while calculating the sighash message.
|
/// 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 {
|
pub enum SignError {
|
||||||
/// Input index out of bounds (actual index, maximum index allowed).
|
/// Input index out of bounds (actual index, maximum index allowed).
|
||||||
IndexOutOfBounds(usize, usize),
|
IndexOutOfBounds(usize, usize),
|
||||||
|
@ -695,7 +696,7 @@ impl fmt::Display for SignError {
|
||||||
use self::SignError::*;
|
use self::SignError::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
IndexOutOfBounds(ind, len) => {
|
IndexOutOfBounds(ref ind, ref len) => {
|
||||||
write!(f, "index {}, psbt input len: {}", ind, len)
|
write!(f, "index {}, psbt input len: {}", ind, len)
|
||||||
}
|
}
|
||||||
InvalidSighashType => write!(f, "invalid sighash type"),
|
InvalidSighashType => write!(f, "invalid sighash type"),
|
||||||
|
@ -706,7 +707,7 @@ impl fmt::Display for SignError {
|
||||||
MismatchedAlgoKey => write!(f, "signing algorithm and key type does not match"),
|
MismatchedAlgoKey => write!(f, "signing algorithm and key type does not match"),
|
||||||
NotEcdsa => write!(f, "attempted to ECDSA sign an non-ECDSA input"),
|
NotEcdsa => write!(f, "attempted to ECDSA sign an non-ECDSA input"),
|
||||||
NotWpkh => write!(f, "the scriptPubkey is not a P2WPKH script"),
|
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"),
|
UnknownOutputType => write!(f, "unable to determine the output type"),
|
||||||
KeyNotFound => write!(f, "unable to find key"),
|
KeyNotFound => write!(f, "unable to find key"),
|
||||||
WrongSigningAlgorithm =>
|
WrongSigningAlgorithm =>
|
||||||
|
|
|
@ -30,7 +30,7 @@ mod message_signing {
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// An error used for dealing with Bitcoin Signed Messages.
|
/// An error used for dealing with Bitcoin Signed Messages.
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum MessageSignatureError {
|
pub enum MessageSignatureError {
|
||||||
/// Signature is expected to be 65 bytes.
|
/// Signature is expected to be 65 bytes.
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub trait FromHexStr: Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hex parsing error
|
/// Hex parsing error
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum FromHexError<E> {
|
pub enum FromHexError<E> {
|
||||||
/// The input was not a valid hex string, contains the error that occurred while parsing.
|
/// The input was not a valid hex string, contains the error that occurred while parsing.
|
||||||
ParseHex(E),
|
ParseHex(E),
|
||||||
|
|
|
@ -1435,7 +1435,7 @@ impl<'de> serde::Deserialize<'de> for LeafVersion {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Detailed error type for taproot builder.
|
/// Detailed error type for taproot builder.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum TaprootBuilderError {
|
pub enum TaprootBuilderError {
|
||||||
/// Merkle tree depth must not be more than 128.
|
/// 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.
|
/// Detailed error type for taproot utilities.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum TaprootError {
|
pub enum TaprootError {
|
||||||
/// Proof size must be a multiple of 32.
|
/// Proof size must be a multiple of 32.
|
||||||
|
|
Loading…
Reference in New Issue