-
Notifications
You must be signed in to change notification settings - Fork 281
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
Introduce write_err
macro
#446
Conversation
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.
While strictly correct, I'd like to see write_err!()
used.
src/key.rs
Outdated
impl std::error::Error for InvalidParityValue {} | ||
impl std::error::Error for InvalidParityValue { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
None |
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.
Is the point of this to express "no, we didn't forget about this"?
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 going to remove this, I did not think thoroughly enough when doing this to realise I was just adding the default implementation :) Thanks
src/lib.rs
Outdated
NotEnoughMemory => "secp: not enough memory allocated", | ||
InvalidPublicKeySum => "secp: the sum of public keys was invalid or the input vector lengths was less than 1", | ||
InvalidParityValue(_) => "couldn't create parity", | ||
}) |
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 believe it was previously more readable, but we should use write_err!()
anyway. I think it's OK to copy-paste the macro?
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.
Done, as suggested. Cheers.
The current display code for `Error` is a little unusual. We typically just implement `Display` and if a `str` is needed use `format!`. Improve the `Error` type by doing - Remove the `as_str` function and implement `Display` directly. - Remove the 'secp: ' prefix of all the error messages. - Use a newly defined macro `write_err` that writes the error if `std` feature is not enabled so that no-std builds do not loose error info. Note: The `write_err` macro is currently being introduced in `rust-bitcoin` also. Elect to just duplicate it here and not share it between the crates.
4fb4fa0
to
946cd83
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 946cd83 nice!
Introduce
write_err
macro and improve theDisplay
implementation onError
.This PR is re-written after review below. The
std::error::Error
implementation is removed in favour of #409. Now only includes theDisplay
stuff.