-
Notifications
You must be signed in to change notification settings - Fork 83
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
Make core Error
enums less specific
#270
Comments
A thought: ideally, internal functions that do use an |
In #164, there was some push-back against using
In other words, programmatic logic based on which error occurred is non-existent in all these projects. This tells me that the most important use case for our errors is aiding in debugging; either host chain implementations, or relayers such as Hermes. Therefore, I feel like our error system should focus on producing great human-readable error diagnostics, which is exactly what libraries such as I would love the hear people's thoughts on this! |
My take, Maybe you have a way of implementing And, It would be great if you elaborate more on the limitation we face with the current error enum. Couldn’t we refactor it for a better one? I see the fact you mentioned that IBC-rs errors are not used well in projects, but I think the main reason is they are still in development (e.g. bunch of Actually, I am a bit concerned, as IIRC we just revamped our error system. If we switch to |
I agree with Fahrad, and believe he has a good point wrt codebases not handling errors properly when under heavy development. Moreover, I too am not sure that I see how anyhow can improve the quality of the errors reported over custom error enums. Perhaps you could into more details about the problems you are seeing? |
I believe I found a good strategy for a better error systems (discussion with @romac heavily influenced the design). The new system recognizes 2 "error sources":
Host errorsThe host error type will be defined by the host. Specifically, we'd make it an associated type of trait ValidationContext {
type Error;
fn host_timestamp(&self) -> Result<Time, Self::Error>;
} Protocol errorsThe type for protocol errors would roughly be a cleaned up version of our current
Top-level error typeOur top-level error type, returned by enum Error<E> {
Host(E),
Protocol(CleanedUpContextError),
} As an example, I would expect the user code to look like: match dispatch(...) {
Host(err) => /* optionally handle my errors */,
Protocol(err) => /* log errors */
} Internal logic based on errors from the hostThis section borrows the great idea presented in this sled.rs's blog post. In a few instances we need to perform some logic based on the specific error returned from the host. For example, when the packet commitment is not present during acknowledgement processing, we want to return early without an error. We currently return early for all errors, but ideally we'd distinguish the "packet commitment not present" error from all other errors, and only return early for the "packet commitment not present" error. Here's where we'd use sled's idea. fn get_packet_commitment(
&self,
commitment_path: &CommitmentPath,
) -> Result<Result<PacketCommitment, CommitmentError>, Self::Error>;
enum CommitmentError {
NotFound,
} The benefit of this signature is that our internal code would look like: // note how the outer `Self::Error` gets propagated out, and we
// match on the inner error that we care about
if matches!(ctx_a.get_packet_commitment(&commitment_path_on_a)?, CommitmentError::NotFound) {
return Ok(());
}; And that's it! I also expect cleaning up |
I liked the idea of separating the error from the sources. So, we only have to take care of ours without assuming anything about the hosts! That’s perfect in my view. There are just a few questions it may help to clarify some of the details:
And a suggestion: |
The "top-level" type is just the type that
Errors such as
Returning an error doesn't mean it's "illegitimate". if matches!(ctx_a.get_packet_commitment(&commitment_path_on_a)?, CommitmentError::NotFound) {
return Ok(());
}; tells me a ton more about what's going on; I see that the commitment was not found directly at the call site. Compare to your suggested signature: if ctx_a.get_packet_commitment(&commitment_path_on_a)?.is_none() {
return Ok(());
};
So using a |
Follow-up to #255.
Our
Error
enums have too many variants. We should drastically condense them following the ideas described here.Tasks
HostError
type #1320Any
toMsgEnvelope
#950The text was updated successfully, but these errors were encountered: