Skip to content

Commit 959a522

Browse files
committed
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.
1 parent 8a997b1 commit 959a522

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
@@ -137,6 +137,7 @@ where
137137
/// much as it could be; patches welcome if more detailed errors
138138
/// would help you.
139139
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
140+
#[non_exhaustive]
140141
pub enum Error {
141142
/// Something did a non-minimal push; for more information see
142143
/// `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)