Use failure for error management#23
Conversation
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
|
Thanks, I will try to come across this at a later time. |
I totally agree that Get should return an Option instead of error for this case. Let's change it to what you just suggested. Although I'm still not quite confident about the whole error things yet, but I agree that users usually do not care the detail error types. The whole reason behind structured error types was for the client itself to properly handle certain errors, for example automatically retried or refresh region cache etc. As we are not working on transactional client yet, we have plenty of time to decide what we are going to do for transactional api. |
|
Regarding these:
Seems
I'd also note that the I think catering to the usual case is usually fine, but we must also be able to cater to the unusual case for some users. If this is as simple as making |
I think the forward compatibility that failure doc claims is achieved by keeping ErrorKind private. Suppose ErrorKind is public, and the crate user does an exhaustive match, then we adding a variant breaks the program.
I agree we probably need to support those unusual users. I am neutral about the visibility of ErrorKind. I am going to make it public if there aren't any other worries. |
In this case they are explicitly opting into this breaking because they want to exhaustively match. If they want to avoid this they can add a |
Yes. That's rare and can be avoided. So the compatibility is not a big problem. |
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
|
Merged master and |
|
For backward compatibility with the ErrorKind enum you could make it an "open enum", by just adding a But it looks good to me. While I do like most of the failure crate, the amount of boilerplate is a drag. Also, I still don't see the advantage of Error + ErrorKind over error enums, even after reading https://rust-lang-nursery.github.io/failure/error-errorkind.html. LGTM. |
|
@sticnarf We have a conflict. 😭 Do you think you can resolve it then we can merge? |
|
@Hoverbear Done |
|
Force merging due to CI. |
|
THanks for this contribution @sticnarf , I really appreciate it. :) It's so nice to have folks like you involved. |
As mentioned in #10, we are going to use failure for error management.
This PR is almost a mechanical transformation of @sunxiaoguang 's previous work, leaving furthur questions to other PRs.
Questions about current errors:
Should
ErrorKindbe public to users? Currently, I think the caller can do nothing effective at runtime when receiving an Error (exceptNoSuchKey, discussed below). The caller can just log the error and try again. Therefore, it seems useless to exposeErrorKindto users. Keeping it private helps with forward compatibility, however we may not need that.Should we treat
NoSuchKeyas an error? People might need to know whether a key exists. Now, they have to match from the error variants and see if it is aNoSuchKey. IMOOption<Value>is a better option for the get api.InternalErrorlooks like a box for all uncategorized errors. Those which relate to PD should have their own error variants in the future.Inconsistency with errors from kvproto.
KeyErroris just a wrapper of the original error, and the others extracts the inner fields.