Skip to content
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

Merged
merged 9 commits into from
Jul 14, 2022
Merged

Conversation

yeastplume
Copy link
Member

This is an update of the change to thiserror from the deprecated failure 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.

@phyro
Copy link
Member

phyro commented Jul 5, 2022

There are some occurrences in the lock files e.g. https://github.com/mimblewimble/grin/blob/master/core/fuzz/Cargo.lock#L312-L330
Should we do something about these?

@yeastplume
Copy link
Member Author

There are some occurrences in the lock files e.g. https://github.com/mimblewimble/grin/blob/master/core/fuzz/Cargo.lock#L312-L330 Should we do something about these?

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.

@phyro
Copy link
Member

phyro commented Jul 5, 2022

Successfully synced a node and tried a basic error. I noticed some RPC calls got a different return type e.g. get_header went from -> Result<BlockHeaderPrintable, ErrorKind>; to -> Result<BlockHeaderPrintable, Error>;. I tried a simple request for a header at height that didn't exist at the time on both master and this branch and they returned the same response

> curl -XPOST -s -w "%{http_code}" -ugrin:(cat ~/.grin/main/.foreign_api_secret) -d '{"jsonrpc": "2.0","method": "get_header","params": [1817338,null,null],"id": 1}' http://127.0.0.1:3413/v2/foreign
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "Err": "NotFound"
  }
}200⏎ 

Do we care if all the error responses are exactly as they were before?

@yeastplume
Copy link
Member Author

Successfully synced a node and tried a basic error. I noticed some RPC calls got a different return type e.g. get_header went from -> Result<BlockHeaderPrintable, ErrorKind>; to -> Result<BlockHeaderPrintable, Error>;. I tried a simple request for a header at height that didn't exist at the time on both master and this branch and they returned the same response

> curl -XPOST -s -w "%{http_code}" -ugrin:(cat ~/.grin/main/.foreign_api_secret) -d '{"jsonrpc": "2.0","method": "get_header","params": [1817338,null,null],"id": 1}' http://127.0.0.1:3413/v2/foreign
{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "Err": "NotFound"
  }
}200⏎ 

Do we care if all the error responses are exactly as they were before?

They can't be the same as before, because thiserror gets rid of ErrorKind. As you demonstrate there, the printed output is okay. Anyone linking directly may need to modify some error handling code, but it's straightforward (will include this in the release notes)

Copy link
Member

@phyro phyro left a 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.

Ok(())
w(&self.chain)?
.compact()
.map_err(|_| Error::Internal("chain error".to_owned()))
Copy link
Member

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

Copy link
Member Author

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))
Copy link
Member

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.

Copy link
Member Author

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)?;
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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);
Copy link
Member

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?

Copy link
Member Author

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.

@yeastplume
Copy link
Member Author

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.

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.

@yeastplume
Copy link
Member Author

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.

@yeastplume yeastplume merged commit a14a8e3 into mimblewimble:master Jul 14, 2022
bayk added a commit to mwcproject/mwc-node that referenced this pull request Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants