From aa9b602dc67732ead5969a9765bba17b10d940e5 Mon Sep 17 00:00:00 2001 From: Innocent Onyemaenu Date: Mon, 6 Jan 2025 22:24:35 +0100 Subject: [PATCH] In #945fcd09 we forgot to update the following: impl fmt::Display trait for ParsePublicKeyError impl std::error::Error for ParsePublicKeyError --- bitcoin/src/crypto/key.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs index e51350afab..d7cb485e6a 100644 --- a/bitcoin/src/crypto/key.rs +++ b/bitcoin/src/crypto/key.rs @@ -1036,7 +1036,14 @@ impl fmt::Display for ParsePublicKeyError { use ParsePublicKeyError::*; match self { Encoding(e) => write_err!(f, "string error"; e), - InvalidChar(char) => write!(f, "hex error {}", char), + InvalidChar(err) => { + let printable = (b' '..=b'~').contains(&err.invalid_char()); + if printable { + write!(f, "hex error: invalid character {} at position {}", char::from(err.invalid_char()), err.pos()) + } else { + write!(f, "hex error: invalid byte 0x{:02x} at position {}", err.invalid_char(), err.pos()) + } + }, InvalidHexLength(got) => write!(f, "pubkey string should be 66 or 130 digits long, got: {}", got), } @@ -1050,7 +1057,8 @@ impl std::error::Error for ParsePublicKeyError { match self { Encoding(e) => Some(e), - InvalidChar(_) | InvalidHexLength(_) => None, + InvalidChar(err) => Some(err), + InvalidHexLength(_) => None, } } }