-
Notifications
You must be signed in to change notification settings - Fork 990
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
Thiserror changeover #3728
Thiserror changeover #3728
Conversation
There are some occurrences in the lock files e.g. https://github.com/mimblewimble/grin/blob/master/core/fuzz/Cargo.lock#L312-L330 |
I've updated the fuzz tests (which I have never looked at) to latest versions of everything, this should remove those references, as well as clean up most of the dependencybot warnings we have against the code. |
Successfully synced a node and tried a basic error. I noticed some RPC calls got a different return type e.g.
Do we care if all the error responses are exactly as they were before? |
They can't be the same as before, because |
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 left some minor comments/questions. Great job, I think this simplifies error handling quite a bit. It's a pretty big change and the error handling logic also touches consensus related errors. I'm not yet sure how well tested error cases are in our tests, but I do hope we have these (I've seen some changes here, but not that many iirc). Since we're not in a hurry to merge this (afaik?), I suggest someone else makes a pass as well when they find time.
api/src/handlers/chain_api.rs
Outdated
Ok(()) | ||
w(&self.chain)? | ||
.compact() | ||
.map_err(|_| Error::Internal("chain error".to_owned())) |
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 this error mapping intended? The previous code uses the ?
and doesn't map the error from what I can tell
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.
all fine, but adding slightly modified version to PR (has to do with From Trait implementation of chain::Error to rest::Error vs missing trait implemention of Result((), Error)... not worth getting into)
api/src/rest.rs
Outdated
self.private_key | ||
)))?; | ||
let keyfile = File::open(&self.private_key).map_err(|e| { | ||
Error::Internal(format!("failed to open file {} {}", self.private_key, e)) |
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 guess that's a more general question regarding the difference in how errors were done before and are done now. We now also print e
to it. Could this produce some kind of information leaking to logs that we may not want? If the answer is "we don't know", that's ok because I understand we don't have people to ask right now.
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.
It could.. answer is 'I don't know'. In this case it's a private key read from a file stored in a string, so I'm going to revert the code that logs it. (the code wouldn't have been able to read it anyhow given this was an error reading the underlying file, but seems obvious it's not something we need to log)
block | ||
.validate(&prev.total_kernel_offset) | ||
.map_err(ErrorKind::InvalidBlockProof)?; | ||
block.validate(&prev.total_kernel_offset)?; |
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.
did we forget to map error to InvalidBlockProof like it was before?
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.
no, it's just implicitly done here now https://github.com/yeastplume/grin/blob/ba7eb9739987fb2687c8b72c3049de0eee3ab183/chain/src/error.rs#L54
|
||
fuzz_target!(|data: &[u8]| { | ||
let mut d = data.clone(); | ||
let _t: Result<UntrustedBlock, ser::Error> = ser::deserialize(&mut d, ser::ProtocolVersion(2)); | ||
let _t: Result<UntrustedBlock, ser::Error> = | ||
ser::deserialize(&mut d, ser::ProtocolVersion(2), DeserializationMode::Full); |
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, we missed these in one of the previous refactorings didn't we? Good this was found and fixed 👍
Do you know if we run any fuzz testing when making a release or on CI?
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.
No, fuzz testing is very manual and I don't think anyone's looked at it in years. I updated all of it because they're small and only took a few minutes to update, so someone can have a look later if they like. If it had been a non-trivial task I would have just removed or disabled them.
Not in a hurry, but the budding GUI code is now dependent on these changes for error display, so would like to get this and the wallet version in soon. |
Think I'm happy with the state of review now, so merging. We'll have a while to shake issues out on the master branch before release anyhow. |
This is an update of the change to
thiserror
from the deprecatedfailure
crate originally proposed by by @trevyn in #3633 (with many thanks for doing this).As noted in that PR, we should be updating from the deprecated crate, and I'd like to make sure the error handling is updated and consistent between the node, wallet and gui code. Will be updating the wallet project similarly.