Add non_exhaustive to all error enums
Adding an error variant to a public enum is an API breaking change, this means making what could be small refactorings or improvements harder. If we use `non_exhaustive` for error types then we mitigate this cost. There is a tradeoff however, downstream users who explicitly match on our public error types must include a wildcard pattern.
This commit is contained in:
parent
99ae48ab01
commit
99f565f932
|
@ -333,6 +333,7 @@ impl Block {
|
||||||
|
|
||||||
/// An error when looking up a BIP34 block height.
|
/// An error when looking up a BIP34 block height.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum Bip34Error {
|
pub enum Bip34Error {
|
||||||
/// The block does not support BIP34 yet.
|
/// The block does not support BIP34 yet.
|
||||||
Unsupported,
|
Unsupported,
|
||||||
|
|
|
@ -137,6 +137,7 @@ where
|
||||||
/// 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(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
|
||||||
|
#[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
|
||||||
/// `https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#Push_operators`
|
/// `https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#Push_operators`
|
||||||
|
|
|
@ -114,6 +114,7 @@ impl fmt::Display for OutPoint {
|
||||||
|
|
||||||
/// An error in parsing an OutPoint.
|
/// An error in parsing an OutPoint.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum ParseOutPointError {
|
pub enum ParseOutPointError {
|
||||||
/// Error in TXID part.
|
/// Error in TXID part.
|
||||||
Txid(hashes::hex::Error),
|
Txid(hashes::hex::Error),
|
||||||
|
|
|
@ -47,6 +47,7 @@ use crate::network::{message_blockdata::Inventory, address::{Address, AddrV2Mess
|
||||||
|
|
||||||
/// Encoding error
|
/// Encoding error
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// And I/O error
|
/// And I/O error
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
|
|
|
@ -50,6 +50,7 @@ pub mod stream_reader;
|
||||||
|
|
||||||
/// Network error
|
/// Network error
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// And I/O error
|
/// And I/O error
|
||||||
Io(io::Error),
|
Io(io::Error),
|
||||||
|
|
|
@ -53,6 +53,7 @@ use crate::util::schnorr::{TapTweak, UntweakedPublicKey, TweakedPublicKey};
|
||||||
|
|
||||||
/// Address error.
|
/// Address error.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Base58 encoding error.
|
/// Base58 encoding error.
|
||||||
Base58(base58::Error),
|
Base58(base58::Error),
|
||||||
|
|
|
@ -148,6 +148,7 @@ fn denomination_from_str(mut s: &str) -> Option<Denomination> {
|
||||||
|
|
||||||
/// An error during amount parsing.
|
/// An error during amount parsing.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum ParseAmountError {
|
pub enum ParseAmountError {
|
||||||
/// Amount is negative.
|
/// Amount is negative.
|
||||||
Negative,
|
Negative,
|
||||||
|
|
|
@ -29,6 +29,7 @@ use crate::util::{endian, key};
|
||||||
|
|
||||||
/// 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, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Invalid character encountered
|
/// Invalid character encountered
|
||||||
BadByte(u8),
|
BadByte(u8),
|
||||||
|
|
|
@ -457,6 +457,7 @@ pub type KeySource = (Fingerprint, DerivationPath);
|
||||||
|
|
||||||
/// A BIP32 error
|
/// A BIP32 error
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
|
#[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
|
||||||
CannotDeriveFromHardenedKey,
|
CannotDeriveFromHardenedKey,
|
||||||
|
|
|
@ -87,6 +87,7 @@ impl FromStr for EcdsaSig {
|
||||||
|
|
||||||
/// A key-related error.
|
/// A key-related error.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum EcdsaSigError {
|
pub enum EcdsaSigError {
|
||||||
/// Hex encoding error
|
/// Hex encoding error
|
||||||
HexEncoding(hex::Error),
|
HexEncoding(hex::Error),
|
||||||
|
|
|
@ -31,6 +31,7 @@ use crate::util::base58;
|
||||||
|
|
||||||
/// A key-related error.
|
/// A key-related error.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Base58 encoding error
|
/// Base58 encoding error
|
||||||
Base58(base58::Error),
|
Base58(base58::Error),
|
||||||
|
|
|
@ -48,6 +48,7 @@ mod message_signing {
|
||||||
/// An error used for dealing with Bitcoin Signed Messages.
|
/// An error used for dealing with Bitcoin Signed Messages.
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "secp-recovery")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "secp-recovery")))]
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum MessageSignatureError {
|
pub enum MessageSignatureError {
|
||||||
/// Signature is expected to be 65 bytes.
|
/// Signature is expected to be 65 bytes.
|
||||||
InvalidLength,
|
InvalidLength,
|
||||||
|
|
|
@ -67,6 +67,7 @@ pub trait BitArray {
|
||||||
/// A general error code, other errors should implement conversions to/from this
|
/// A general error code, other errors should implement conversions to/from this
|
||||||
/// if appropriate.
|
/// if appropriate.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Encoding error
|
/// Encoding error
|
||||||
Encode(encode::Error),
|
Encode(encode::Error),
|
||||||
|
|
|
@ -33,6 +33,7 @@ pub enum PsbtHash {
|
||||||
}
|
}
|
||||||
/// Ways that a Partially Signed Transaction might fail.
|
/// Ways that a Partially Signed Transaction might fail.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Magic bytes for a PSBT must be the ASCII for "psbt" serialized in most
|
/// Magic bytes for a PSBT must be the ASCII for "psbt" serialized in most
|
||||||
/// significant byte order.
|
/// significant byte order.
|
||||||
|
|
|
@ -82,6 +82,7 @@ pub struct Output {
|
||||||
/// Error happening when [`TapTree`] is constructed from a [`TaprootBuilder`]
|
/// Error happening when [`TapTree`] is constructed from a [`TaprootBuilder`]
|
||||||
/// having hidden branches or not being finalized.
|
/// having hidden branches or not being finalized.
|
||||||
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
|
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum IncompleteTapTree {
|
pub enum IncompleteTapTree {
|
||||||
/// Indicates an attempt to construct a tap tree from a builder containing incomplete branches.
|
/// Indicates an attempt to construct a tap tree from a builder containing incomplete branches.
|
||||||
NotFinalized(TaprootBuilder),
|
NotFinalized(TaprootBuilder),
|
||||||
|
|
|
@ -223,6 +223,7 @@ mod display_from_str {
|
||||||
/// Error encountered during PSBT decoding from Base64 string.
|
/// Error encountered during PSBT decoding from Base64 string.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum PsbtParseError {
|
pub enum PsbtParseError {
|
||||||
/// Error in internal PSBT data structure.
|
/// Error in internal PSBT data structure.
|
||||||
PsbtEncoding(Error),
|
PsbtEncoding(Error),
|
||||||
|
|
|
@ -261,6 +261,7 @@ impl SchnorrSig {
|
||||||
|
|
||||||
/// A schnorr sig related error.
|
/// A schnorr sig related error.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum SchnorrSigError {
|
pub enum SchnorrSigError {
|
||||||
/// Base58 encoding error
|
/// Base58 encoding error
|
||||||
InvalidSighashType(u8),
|
InvalidSighashType(u8),
|
||||||
|
|
|
@ -167,6 +167,7 @@ impl str::FromStr for SchnorrSighashType {
|
||||||
|
|
||||||
/// Possible errors in computing the signature message.
|
/// Possible errors in computing the signature message.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
|
#[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
|
||||||
/// like the ones used in methods `*_signature_hash` do not error.
|
/// like the ones used in methods `*_signature_hash` do not error.
|
||||||
|
|
|
@ -969,6 +969,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, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
#[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.
|
||||||
InvalidMerkleTreeDepth(usize),
|
InvalidMerkleTreeDepth(usize),
|
||||||
|
@ -1030,6 +1031,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, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub enum TaprootError {
|
pub enum TaprootError {
|
||||||
/// Proof size must be a multiple of 32.
|
/// Proof size must be a multiple of 32.
|
||||||
InvalidMerkleBranchSize(usize),
|
InvalidMerkleBranchSize(usize),
|
||||||
|
|
Loading…
Reference in New Issue