Skip to content

Commit 67e583c

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#1026: Add non_exhaustive to all error enums
99f565f Add non_exhaustive to all error enums (Tobin C. Harding) Pull request description: 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. ACKs for top commit: apoelstra: ACK 99f565f Kixunil: ACK 99f565f Tree-SHA512: ff329f87d52b3fbe24654f32e4062ddae73173cba5a13d511591158e68ee278e9bdc0a70a3e0b42d6606b369255923f9c46d8b3d1b2ff75f8461a82567df80cd
2 parents c8ae04e + 959a522 commit 67e583c

File tree

19 files changed

+20
-0
lines changed

19 files changed

+20
-0
lines changed

src/blockdata/block.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ impl Block {
333333

334334
/// An error when looking up a BIP34 block height.
335335
#[derive(Debug, Clone, PartialEq, Eq)]
336+
#[non_exhaustive]
336337
pub enum Bip34Error {
337338
/// The block does not support BIP34 yet.
338339
Unsupported,

src/blockdata/script.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ where
138138
/// much as it could be; patches welcome if more detailed errors
139139
/// would help you.
140140
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
141+
#[non_exhaustive]
141142
pub enum Error {
142143
/// Something did a non-minimal push; for more information see
143144
/// `https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#Push_operators`

src/blockdata/transaction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ impl fmt::Display for OutPoint {
114114

115115
/// An error in parsing an OutPoint.
116116
#[derive(Clone, PartialEq, Eq, Debug)]
117+
#[non_exhaustive]
117118
pub enum ParseOutPointError {
118119
/// Error in TXID part.
119120
Txid(hashes::hex::Error),

src/consensus/encode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use crate::network::{message_blockdata::Inventory, address::{Address, AddrV2Mess
4747

4848
/// Encoding error
4949
#[derive(Debug)]
50+
#[non_exhaustive]
5051
pub enum Error {
5152
/// And I/O error
5253
Io(io::Error),

src/network/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub mod stream_reader;
5050

5151
/// Network error
5252
#[derive(Debug)]
53+
#[non_exhaustive]
5354
pub enum Error {
5455
/// And I/O error
5556
Io(io::Error),

src/util/address.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use crate::util::schnorr::{TapTweak, UntweakedPublicKey, TweakedPublicKey};
5353

5454
/// Address error.
5555
#[derive(Debug, PartialEq, Eq, Clone)]
56+
#[non_exhaustive]
5657
pub enum Error {
5758
/// Base58 encoding error.
5859
Base58(base58::Error),

src/util/amount.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ fn denomination_from_str(mut s: &str) -> Option<Denomination> {
148148

149149
/// An error during amount parsing.
150150
#[derive(Debug, Clone, PartialEq, Eq)]
151+
#[non_exhaustive]
151152
pub enum ParseAmountError {
152153
/// Amount is negative.
153154
Negative,

src/util/base58.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::util::{endian, key};
2929

3030
/// An error that might occur during base58 decoding
3131
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
32+
#[non_exhaustive]
3233
pub enum Error {
3334
/// Invalid character encountered
3435
BadByte(u8),

src/util/bip32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ pub type KeySource = (Fingerprint, DerivationPath);
457457

458458
/// A BIP32 error
459459
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
460+
#[non_exhaustive]
460461
pub enum Error {
461462
/// A pk->pk derivation was attempted on a hardened key
462463
CannotDeriveFromHardenedKey,

src/util/ecdsa.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl FromStr for EcdsaSig {
8787

8888
/// A key-related error.
8989
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
90+
#[non_exhaustive]
9091
pub enum EcdsaSigError {
9192
/// Hex encoding error
9293
HexEncoding(hex::Error),

0 commit comments

Comments
 (0)