-
Notifications
You must be signed in to change notification settings - Fork 82
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
Refactor error system #255
Refactor error system #255
Conversation
Do you have a better description of the error? /// Ics04 channel error(`{0}`)
Ics04Channel(channel_error::Error),
/// invalid port identifier `{context}` error(`{validation_error}`)
InvalidPortId {
context: String,
validation_error: ValidationError,
},
/// invalid channel identifier `{context}` error(`{validation_error}`)
InvalidChannelId {
context: String,
validation_error: ValidationError,
}, |
Note: hopefully our solution here also addresses #23. I'm still thinking about how to make everything work together (logs discarded on error issue, no_std support, error sources, small number of EDIT: Actually #23 fixed by the new |
use displaydoc::Display; | ||
|
||
#[derive(Debug, Display)] | ||
pub enum ContextError { |
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 do not know if my understanding of this is in line with the requirements
#[derive(Debug, Display)] | ||
pub enum ClientError { | ||
/// unknown client type: `{client_type}` | ||
UnknownClientType { client_type: String }, |
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.
Having thought about this some more, I like the direction this PR is taking. IMO what's left to be done is:
- Remove all unused errors such as this one. Once this is done, we can additionally look to combine redundant errors.
- "Roll our own backtrace", as @hu55a1n1 suggested. We should make sure to use the same convention everywhere, as you started doing here:
<error message>: {0}
(for when the error argument is anotherError
). Whenstd::error::Error
makes it intocore
, we can start usingthiserror
. - Make sure there's a
Error::Other
variant for host methods to use. This PR is getting big enough, we can change host functions in another PR.
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.
When
std::error::Error
makes it into core, we can start usingthiserror
Currentlythiserror
can not be used in no_std,thiserror::Error
I think the implementation of this macro can not be used in the current no_std environment, and the current use ofdisplaydoc
I think similar tothiserror
except that there is no error backtrace, but here we have implementedstd::error::Error
.
#[cfg(feature = "std")]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match &self {
Error::InvalidHeader { error: e, .. } => Some(e),
Error::InvalidTendermintTrustThreshold(e) => Some(e),
Error::InvalidChainIdentifier(e) => Some(e),
Error::InvalidChainId { error: e, .. } => Some(e),
Error::InvalidRawHeader(e) => Some(e),
Error::Decode(e) => Some(e),
Error::TimestampOverflow(e) => Some(e),
_ => None,
}
}
}
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.
when thiserror
support we just add #derive[thiserror::Error]
can remove below this.
#[cfg(feature = "std")]
impl std::error::Error for Error {}
Requested additional input from @blasrodri; let's hold until then |
I like the idea of getting rid of Overall, I think this PR reflects the goals of #164 . |
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.
Thank you for this amazing work; we're getting really close to the finish line! 😃
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.
Awesome work :)
thx guys |
* Redefine Ics20Error by displaydoc * Redefine Ics02Error by displaydoc * Update client_state.rs * Redefine Ics07Error by displaydoc * Redefine Ics03Error by displaydoc * Redefine Ics04Error by displaydoc * Redefine Ics05Error by displaydoc * Redefine Ics23Error by displaydoc * Redefine Ics24Error by displaydoc * Redefine Ics26Error by displaydoc * Redefine Ics18Error by displaydoc * Redefine ParseFailure Error * Redefine HeightError * Redefine ProofError * Redefine SignerError * Redefine TimestampOverflowError, ParseTimestampError * Redefine event Error * update ics03Error * Update Ics04Error * Update Ics26Error * Remove flex-error * Update error.rs * Create 164-refactor-error-system.md * Impl std::erorr::Error for IbcError * Add #![allow(clippy::result_large_err)] * Rename Ics02Error to ClientError * Rename Ics03Error to ConnectionError * Disassembling out PacketError * Rename Ics04Error to ChannelError * Rename Ics05Error to PortError * Rename Ics23Error to CommitmentError * Rename Ics26Error to RouterError * Rename Ics18Error to RelayerError * Rename Ics20Error to TokenTransferError * Add ContextError for ValidationContext and ExecutionContext * Update RouterError * fix clippy * Update context.rs * Update lib.rs * Secondary error display output * Remove unused Error variant * Remove unused Error variant * Update 164-refactor-error-system.md
Closes: #164
Description
PR author checklist:
unclog
.docs/
).Reviewer checklist:
Files changed
in the GitHub PR explorer.