-
Notifications
You must be signed in to change notification settings - Fork 831
Add new hex parse error variant #1584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new hex parse error variant #1584
Conversation
3c5b625
to
a705e76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from naming this looks OK.
bitcoin/src/bip32.rs
Outdated
@@ -455,6 +455,8 @@ pub enum Error { | |||
Base58(base58::Error), | |||
/// Hexadecimal decoding error | |||
Hex(hex::Error), | |||
/// `PublicKey` hex should be 66 or 130 digits long. | |||
InvalidPublicKeyHex(usize), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not called InvalidHexLength
as below? That one is more clear.
Also, we have this problem everywhere: I think all enum variants should use named fields except for inner errors (e.g. hex::Error
in this case) which are obvious enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put PublicKey
in the name to future proof the varian because the 66/130 in the comments and output are pubkey specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain a bit more what you're future-proofing against?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went digging into the code and my brain to try and remember what I was thinking when I wrote both this PR and the comment above. Seems I misspoke in the comment, I believe I chose the name because the error enum in the bip32
module is more general than just parsing keys, where as in thekey
module the error enum is only related to keys. Moreover the InvalidHexLength
is only returned when parsing pubkeys. I've changed the bip32
error variant to InvalidPublicKeyHexLength
to better show that it is the same as key::InvalidHexLength
but with pubkey in the variant to disambiguate in like other bip32::Error
variants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think I understand, makes sense.
a705e76
to
024f704
Compare
Recently we used an error type that holds only one expected hex string length when parsing but for `PublicKey`s we have two (66 and 130). Add a new error variant to express the error. Requires adding a variant to `bip32` for the same thing. Fix: rust-bitcoin#1281
024f704
to
877f9af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 877f9af
@@ -473,6 +475,7 @@ impl fmt::Display for Error { | |||
write!(f, "encoded extended key data has wrong length {}", len), | |||
Error::Base58(ref e) => write_err!(f, "base58 encoding error"; e), | |||
Error::Hex(ref e) => write_err!(f, "Hexadecimal decoding error"; e), | |||
Error::InvalidPublicKeyHexLength(got) => write!(f, "PublicKey hex should be 66 or 130 digits long, got: {}", got), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use user friendly descriptions rather than type names in error messages but I guess there are other instances, so we may want to do complete audit and cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are on the topic, error messages should not be capitialised, right? I always forget and we have so many of both forms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted however not to use types in error messages. Will leave it as it is for now since upcoming error work is imminent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error messages should not be capitialised, right?
I think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 877f9af
Recently we used an error type that holds only one expected hex string length when parsing but for
PublicKey
s we have two (66 and 130). Add a new error variant to express the error. Requires adding a variant tobip32
for the same thing.Fix: #1281