-
Notifications
You must be signed in to change notification settings - Fork 9
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
Hide all error internals #44
Conversation
In preparation for adding a bunch more error types move the current ones out of `parse` into `error`.
dee6b08
to
12092e5
Compare
Man, I forget if we decided struct errors are supposed to have EDIT: Found it, they are supposed to be: rust-bitcoin/rust-secp256k1#635 (comment) |
12092e5
to
a05458f
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 a05458f
Just a few things that would be nice to clean up.
src/iter.rs
Outdated
let loh = (lo as char).to_digit(16).ok_or(HexToBytesError::InvalidChar(lo))?; | ||
let hih = (hi as char) | ||
.to_digit(16) | ||
.ok_or(HexToBytesError::InvalidChar(InvalidCharError { invalid: hi }))?; |
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.
You can keep it short by writing ok_or(InvalidCharError { invalid: hi })?;
thanks to the conversion made by ?
.
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 back and forth'ed on this a bunch of times (literally added and remove code). It works sometimes and in some places it didn't so I went with uniform and wrote it out fully everywhere. I"ll have another go though.
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.
Oh I misspoke, you suggestion is clearly better. I was referring to the into
case below.
#[derive(Debug, Copy, Clone, PartialEq, Eq)] | ||
#[non_exhaustive] |
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.
This is not needed when at least one field is not pub
but I could understand if someone wants to avoid us forgetting to add it in the future.
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'm inclined to put it on every struct regardless because it makes scanning the error types quicker. However, this code is plain old sloppy, I've been not adding Copy
when using non_exhaustive
.
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 naming error type *Error
is much better. There are other types that need to be non_exhaustive
and are not error types.
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 don't follow your comment, all errors are suffixed with Error
. I'll remove the non_exhaustive
from all struct errors that exist solely to hide internals. On further thought today it is strange to have unneeded non_exhaustive
and there will always be private fields since that is the whole point of these types.
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.
Yes, they are and should continue to be. That's my point rg 'struct [A-Za-z0-9]*Error' is better than
rg non_exhaustive`
|
||
/// Purported hex string had odd length. | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq)] | ||
#[non_exhaustive] |
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.
Also not needed
Hide the internals of all errors by wrapping enum variant internals in structs.
a05458f
to
af04208
Compare
All suggestions implemented @Kixunil except removing |
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 af04208
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 af04208
Please don't merge yet, I want to remove the unnecessary |
lol @tcharding you were just a bit too late, sorry |
Ha! I thought you might have started the merge process soon as you acked. I'll fix as a follow up. |
Before we do v1.0 we want to hide all the error internals so that we can modify/improve them without breaking the public API.
Please pay particular attention to the
Display
strings because we they are considered part of the public API so we don't want to change them willy-nilly. Of note, because the enums have inner structs it was difficult to not duplicate the error message.Resolve: #42