Skip to content

Commit 84b2c50

Browse files
committed
Merge #165: Improve error display for invalid witness version
e988f34 Improve error display for invalid witness version (Tobin C. Harding) d692972 Add rustfmt::skip to Display impl (Tobin C. Harding) Pull request description: We have two errors that cover invalid witness version, for one we print the field element which can be confusing for some values and for the other we omit the invalid version all together - we can do better. Print the field element as well as the integer value when displaying the two invalid witness version errors. Fix: #162 ACKs for top commit: apoelstra: ACK e988f34 Tree-SHA512: 93d666f396c536d6348cf793b74c27363eeacec02c0a7a4ec53786778f7c64c393bad90fe10b718f872d61deb355de4b18f4fd8a66e35a1f53e09ced2cbe7c0b
2 parents b7642a6 + e988f34 commit 84b2c50

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/primitives/decode.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,20 +589,18 @@ pub enum SegwitHrpstringError {
589589
Checksum(ChecksumError),
590590
}
591591

592+
#[rustfmt::skip]
592593
impl fmt::Display for SegwitHrpstringError {
593594
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
594595
use SegwitHrpstringError::*;
595596

596597
match *self {
597598
Unchecked(ref e) => write_err!(f, "parsing unchecked hrpstring failed"; e),
598599
NoData => write!(f, "no data found after removing the checksum"),
599-
TooLong(len) => write!(
600-
f,
601-
"encoded length {} exceeds spec limit {} chars",
602-
len,
603-
segwit::MAX_STRING_LENGTH
604-
),
605-
InvalidWitnessVersion(fe) => write!(f, "invalid segwit witness version: {}", fe),
600+
TooLong(len) =>
601+
write!(f, "encoded length {} exceeds spec limit {} chars", len, segwit::MAX_STRING_LENGTH),
602+
InvalidWitnessVersion(fe) =>
603+
write!(f, "invalid segwit witness version: {} (bech32 character: '{}')", fe.to_u8(), fe),
606604
Padding(ref e) => write_err!(f, "invalid padding on the witness data"; e),
607605
WitnessLength(ref e) => write_err!(f, "invalid witness length"; e),
608606
Checksum(ref e) => write_err!(f, "invalid checksum"; e),

src/primitives/segwit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ pub fn validate_witness_program_length(
6565
#[non_exhaustive]
6666
pub struct InvalidWitnessVersionError(pub Fe32);
6767

68+
#[rustfmt::skip]
6869
impl fmt::Display for InvalidWitnessVersionError {
6970
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
70-
write!(f, "field element does not represent a valid witness version")
71+
write!(f, "invalid segwit witness version: {} (bech32 character: '{}')", self.0.to_u8(), self.0)
7172
}
7273
}
7374

0 commit comments

Comments
 (0)