Skip to content

Commit

Permalink
Improve error display for invalid witness version
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tcharding committed Jan 7, 2024
1 parent c5c028e commit d9bb03e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/primitives/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@ impl fmt::Display for SegwitHrpstringError {
len,
segwit::MAX_STRING_LENGTH
),
InvalidWitnessVersion(fe) => write!(f, "invalid segwit witness version: {}", fe),
InvalidWitnessVersion(fe) =>
write!(f, "invalid segwit witness version: {} (fe32='{}')", fe.to_u8(), fe),
Padding(ref e) => write_err!(f, "invalid padding on the witness data"; e),
WitnessLength(ref e) => write_err!(f, "invalid witness length"; e),
Checksum(ref e) => write_err!(f, "invalid checksum"; e),
Expand Down
2 changes: 1 addition & 1 deletion src/primitives/segwit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct InvalidWitnessVersionError(pub Fe32);

impl fmt::Display for InvalidWitnessVersionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "field element does not represent a valid witness version")
write!(f, "invalid segwit witness version: {} (fe32='{}')", self.0.to_u8(), self.0)
}
}

Expand Down

0 comments on commit d9bb03e

Please sign in to comment.