-
Notifications
You must be signed in to change notification settings - Fork 26
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
RFC: Make ErrNotFound a struct and include IsNotFound helper #33
Conversation
The IsNotFound helper allows the error to be wrapped by using pkg/errors.Cause(...).
@kevina each package should be able to have its own NotFoundError. We should be checking them based on the "Assert errors for behaviour, not type" section of this: https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully |
@whyrusleeping what is the benefit of that? No other error gets this special treatment and it adds a lot of (in by view) unnecessary boilerplate code to the merkedag package (currently still is go-ipfs) that checks if it is IsNotFound from the blockstore and then converts it to its own. The IsNotFound is basically asserting based on behavior. |
For example instead of: b, err := n.Blocks.GetBlock(ctx, c)
if err != nil {
if err == bserv.ErrNotFound {
return nil, ipld.ErrNotFound
}
return nil, fmt.Errorf("Failed to get block for %s: %v", c, err)
} I think we should just use some think like this: import "https://github.com/pkg/errors"
...
b, err := n.Blocks.GetBlock(ctx, c)
if err != nil {
return nil, errors.Wrap(err, "merkledag: get failed")
} |
@kevina aside from the fact that there is value in being able to distinguish where exactly there error is from. With this method, you get silent failures if packages change. (if package hashes change, the equality of the errors fails) |
@whyrusleeping I am not following the second argument. If you don't like where you think I am going with this then please outline what you would like to see. I have given you what I think will improve at least the errors when a CID is not found in a by retuning the CID with the error and allowing it to be wrapped with additional information, including a backtrace with the use of I am fine with a blockstore having its own I can also just leave the blockstore alone and only change the ErrNotFound error from the merkledag package (in
|
Based on #33, taking advantage of the rather new Is() methods from the errors package to check for equality.
The IsNotFound helper allows the error to be wrapped by using pkg/errors.Cause(...).
Next Steps:
DO NOT MERGE until steps 1 and 2 are done in case of problems.
Closes ipfs/kubo#4468
Also See: ipfs/kubo#4099