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

Use flex-error to define errors #988

Merged
merged 71 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
ec73111
Experiment on using flex-error to define errors
soareschen May 25, 2021
c34c51d
Fix error messages
soareschen May 25, 2021
d99b4e3
Fix clippy
soareschen May 25, 2021
91a2d53
Update flex-error version
soareschen May 27, 2021
3895e42
Use flex-error on ics18_relayer
soareschen Jun 7, 2021
6152d90
Use flex-error for ics02_client
soareschen Jun 7, 2021
4b3addd
Fix formatting
soareschen Jun 7, 2021
3063f27
Manual fix formatting in macros
soareschen Jun 7, 2021
8bd683e
Use flex-error for ics03_connection
soareschen Jun 8, 2021
1fbe10e
Use flex-error for ics04_channel
soareschen Jun 10, 2021
6b397f1
Remove Infallible and implement Into for Height directly
soareschen Jun 11, 2021
8da67df
Fix failing test
soareschen Jun 11, 2021
becf13e
Use flex-error for ics20_fungible_token_transfer
Jun 11, 2021
83b01ad
Use flex-error for ics07_tendermint
Jun 11, 2021
e935faa
Use displaydoc for ics24_host
Jun 11, 2021
969c91f
Use by flex-error for timestamp
Jun 11, 2021
2bc323c
Merge branch 'soares/flex-error' of github.com:informalsystems/ibc-rs…
Jun 11, 2021
50fbfef
update ...
Jun 11, 2021
bb79d64
Use flex-error for ics23_commitment
Jun 11, 2021
af98a01
Use displaydoc for Relayer
Jun 16, 2021
79f0662
Use flex-error for ics24_host
Jun 16, 2021
46af54f
fix some bug
Jun 16, 2021
70d38ee
Get rid of some Box<dyn std::error::Error> sources
soareschen Jun 16, 2021
9c59c4b
fix Clippy
Jun 17, 2021
cb1980d
foramt code
Jun 17, 2021
476d6ab
Fix errors
soareschen Jun 17, 2021
277c8f5
Revert changes in Cargo.toml
soareschen Jun 17, 2021
4538d33
Propagate some ignored error sources
soareschen Jun 17, 2021
385c945
Merge branch 'DaviRain-Su/flex-error' into soares/flex-error
soareschen Jun 17, 2021
497cddc
Merge remote-tracking branch 'origin/master' into soares/flex-error
soareschen Jun 17, 2021
da1d6fd
Get rid of some Box<dyn std::error::Error>
soareschen Jun 17, 2021
657df43
Refactoring event attribute macros
soareschen Jun 17, 2021
5a8c1db
Remove all use of events attributes macros
soareschen Jun 17, 2021
65d3465
Remove all Box<dyn std::error::Error> from ibc crate
soareschen Jun 18, 2021
6f7645c
Merge remote-tracking branch 'origin/master' into soares/flex-error
soareschen Jun 18, 2021
dac0c5d
Refactoring errors in relayer
soareschen Jun 18, 2021
08f69e1
Finish refactoring main relayer errors
soareschen Jun 18, 2021
5ade25f
Use flex-error for keyring errors
soareschen Jun 21, 2021
9884499
Use flex-error for ChannelError and relayer_cli::Error
soareschen Jun 21, 2021
da570c8
Use flex-error for ForeignClientError
soareschen Jun 22, 2021
b129b07
Use flex-error for LinkError
soareschen Jun 23, 2021
1949b79
Merge branch 'master' into soares/flex-error
soareschen Jun 23, 2021
96f74e4
Fix test
soareschen Jun 23, 2021
0457d5c
Use flex-error for ConnectionError
soareschen Jun 23, 2021
76e5790
Finished removing all remaining legacy errors
soareschen Jun 23, 2021
e6892a1
Remove obsolete Fail errors
soareschen Jun 23, 2021
19c1dcd
Remove redundant DisplayOnly
soareschen Jun 23, 2021
fcb9ee0
Simplify external error sources specification
soareschen Jun 24, 2021
6e732f8
Removing last few Box<dyn std::error::Error> sources
soareschen Jun 24, 2021
ddab968
Merge branch 'master' into soares/flex-error
soareschen Jun 29, 2021
56d7f29
Merge branch 'master' into soares/flex-error
soareschen Jul 20, 2021
a9a5380
Merge remote-tracking branch 'origin/master' into soares/flex-error
soareschen Jul 20, 2021
e83a283
Use generic version of channel send error constructor
soareschen Jul 20, 2021
8d0c71c
Merge branch 'master' into soares/flex-error
soareschen Jul 20, 2021
27e4239
Minor improvements
soareschen Jul 20, 2021
c3bf3e6
Merge branch 'master' into soares/flex-error
romac Jul 20, 2021
df2a390
Update namespace generated by flex-error
soareschen Jul 21, 2021
61d6b53
Merge remote-tracking branch 'origin/master' into soares/flex-error
soareschen Jul 21, 2021
d0cbdf8
Fix clippy
soareschen Jul 21, 2021
8f75a64
Introduce ObjectError to replace Box<dyn std::error::Error>
soareschen Jul 21, 2021
6f39dce
Fix clippy
soareschen Jul 21, 2021
ef770a6
Remove all use of Box<dyn std::error::Error> in relayer crate
soareschen Jul 21, 2021
07df714
Merge remote-tracking branch 'origin/master' into soares/flex-error
soareschen Jul 22, 2021
6668555
Update flex-error to allow documentation in main error
soareschen Jul 22, 2021
c5d9047
Update flex-error
soareschen Jul 23, 2021
0b3bddb
Merge remote-tracking branch 'origin/master' into soares/flex-error
soareschen Jul 23, 2021
a3355d0
Use published version of flex-error
soareschen Jul 23, 2021
89cfbd2
Update flex-error to v0.4.1
soareschen Jul 26, 2021
cd47305
Merge remote-tracking branch 'origin/master' into soares/flex-error
soareschen Jul 26, 2021
4d0926e
Use flex-error/eyre_tracer feature by default
soareschen Jul 26, 2021
efefaa8
Change feature name to eyre_tracer to avoid name conflict with the ey…
soareschen Jul 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exclude = [
"proto-compiler"
]

# [patch.crates-io]
[patch.crates-io]
# tendermint = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
# tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
# tendermint-proto = { git = "https://github.com/informalsystems/tendermint-rs", branch = "master" }
Expand Down
7 changes: 6 additions & 1 deletion modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ description = """
[features]
# This feature grants access to development-time mocking libraries, such as `MockContext` or `MockHeader`.
# Depends on the `testgen` suite for generating Tendermint light blocks.
default = ["std", "eyre_tracer"]
std = [
"flex-error/std"
]
eyre_tracer = ["flex-error/eyre_tracer"]
mocks = [ "tendermint-testgen", "sha2" ]

[dependencies]
# Proto definitions for all IBC-related interfaces, e.g., connections or channels.
ibc-proto = { version = "0.9.0", path = "../proto" }
ics23 = "0.6.5"
anomaly = "0.2.0"
chrono = "0.4.19"
thiserror = "1.0.26"
serde_derive = "1.0.104"
Expand All @@ -36,6 +40,7 @@ dyn-clonable = "0.9.0"
regex = "1"
subtle-encoding = "0.5"
sha2 = { version = "0.9.3", optional = true }
flex-error = { version = "0.4.1", default-features = false }

[dependencies.tendermint]
version = "=0.21.0"
Expand Down
84 changes: 43 additions & 41 deletions modules/src/application/ics20_fungible_token_transfer/error.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
use anomaly::{BoxError, Context};
use thiserror::Error;

use crate::ics04_channel::error as channel_error;
use crate::ics24_host::error::ValidationError;
use crate::ics24_host::identifier::{ChannelId, PortId};

pub type Error = anomaly::Error<Kind>;

#[derive(Clone, Debug, Error, PartialEq, Eq)]
pub enum Kind {
#[error("unrecognized ICS-20 transfer message type URL {0}")]
UnknownMessageTypeUrl(String),
adizere marked this conversation as resolved.
Show resolved Hide resolved

#[error("error raised by message handler")]
HandlerRaisedError,

#[error("sending sequence number not found for port {0} and channel {1}")]
SequenceSendNotFound(PortId, ChannelId),

#[error("missing channel for port_id {0} and channel_id {1} ")]
ChannelNotFound(PortId, ChannelId),

#[error(
"destination channel not found in the counterparty of port_id {0} and channel_id {1} "
)]
DestinationChannelNotFound(PortId, ChannelId),

#[error("invalid port identifier")]
InvalidPortId(String),

#[error("invalid channel identifier")]
InvalidChannelId(String),

#[error("invalid packet timeout height value")]
InvalidPacketTimeoutHeight(String),

#[error("invalid packet timeout timestamp value")]
InvalidPacketTimeoutTimestamp(u64),
}

impl Kind {
pub fn context(self, source: impl Into<BoxError>) -> Context<Self> {
Context::new(self, Some(source.into()))
use flex_error::define_error;

define_error! {
Error {
UnknowMessageTypeUrl
{ url: String }
| e | { format_args!("unrecognized ICS-20 transfer message type URL {0}", e.url) },

Ics04Channel
[ channel_error::Error ]
|_ | { "Ics04 channel error" },

SequenceSendNotFound
{ port_id: PortId, channel_id: ChannelId }
| e | { format_args!("sending sequence number not found for port {0} and channel {1}", e.port_id, e.channel_id) },

ChannelNotFound
{ port_id: PortId, channel_id: ChannelId }
| e | { format_args!("sending sequence number not found for port {0} and channel {1}", e.port_id, e.channel_id) },

DestinationChannelNotFound
{ port_id: PortId, channel_id: ChannelId }
| e | { format_args!("destination channel not found in the counterparty of port_id {0} and channel_id {1} ", e.port_id, e.channel_id) },

InvalidPortId
{ context: String }
[ ValidationError ]
| _ | { "invalid port identifier" },

InvalidChannelId
{ context: String }
[ ValidationError ]
| _ | { "invalid channel identifier" },

InvalidPacketTimeoutHeight
{ context: String }
| _ | { "invalid packet timeout height value" },

InvalidPacketTimeoutTimestamp
{ timestamp: u64 }
| _ | { "invalid packet timeout timestamp value" },
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tendermint_proto::Protobuf;

use ibc_proto::ibc::apps::transfer::v1::MsgTransfer as RawMsgTransfer;

use crate::application::ics20_fungible_token_transfer::error::{Error, Kind};
use crate::application::ics20_fungible_token_transfer::error::Error;
use crate::ics02_client::height::Height;
use crate::ics24_host::identifier::{ChannelId, PortId};
use crate::signer::Signer;
Expand Down Expand Up @@ -54,28 +54,28 @@ impl Msg for MsgTransfer {
impl Protobuf<RawMsgTransfer> for MsgTransfer {}

impl TryFrom<RawMsgTransfer> for MsgTransfer {
type Error = Kind;
type Error = Error;

fn try_from(raw_msg: RawMsgTransfer) -> Result<Self, Self::Error> {
let timeout_timestamp = Timestamp::from_nanoseconds(raw_msg.timeout_timestamp)
.map_err(|_| Kind::InvalidPacketTimeoutTimestamp(raw_msg.timeout_timestamp))?;
.map_err(|_| Error::invalid_packet_timeout_timestamp(raw_msg.timeout_timestamp))?;

let timeout_height = match raw_msg.timeout_height.clone() {
None => Height::zero(),
Some(raw_height) => raw_height.try_into().map_err(|e| {
Kind::InvalidPacketTimeoutHeight(format!("invalid timeout height {}", e))
Error::invalid_packet_timeout_height(format!("invalid timeout height {}", e))
})?,
};

Ok(MsgTransfer {
source_port: raw_msg
.source_port
.parse()
.map_err(|_| Kind::InvalidPortId(raw_msg.source_port.clone()))?,
.map_err(|e| Error::invalid_port_id(raw_msg.source_port.clone(), e))?,
source_channel: raw_msg
.source_channel
.parse()
.map_err(|_| Kind::InvalidChannelId(raw_msg.source_channel.clone()))?,
.map_err(|e| Error::invalid_channel_id(raw_msg.source_channel.clone(), e))?,
token: raw_msg.token,
sender: raw_msg.sender.into(),
receiver: raw_msg.receiver.into(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::application::ics20_fungible_token_transfer::context::Ics20Context;
use crate::application::ics20_fungible_token_transfer::error::{Error, Kind};
use crate::application::ics20_fungible_token_transfer::error::Error;
use crate::application::ics20_fungible_token_transfer::msgs::transfer::MsgTransfer;
use crate::handler::HandlerOutput;
use crate::ics04_channel::handler::send_packet::send_packet;
Expand All @@ -16,22 +16,25 @@ where
let source_channel_end = ctx
.channel_end(&(msg.source_port.clone(), msg.source_channel.clone()))
.ok_or_else(|| {
Kind::ChannelNotFound(msg.source_port.clone(), msg.source_channel.clone())
Error::channel_not_found(msg.source_port.clone(), msg.source_channel.clone())
})?;

let destination_port = source_channel_end.counterparty().port_id().clone();
let destination_channel = source_channel_end
.counterparty()
.channel_id()
.ok_or_else(|| {
Kind::DestinationChannelNotFound(msg.source_port.clone(), msg.source_channel.clone())
Error::destination_channel_not_found(
msg.source_port.clone(),
msg.source_channel.clone(),
)
})?;

// get the next sequence
let sequence = ctx
.get_next_sequence_send(&(msg.source_port.clone(), msg.source_channel.clone()))
.ok_or_else(|| {
Kind::SequenceSendNotFound(msg.source_port.clone(), msg.source_channel.clone())
Error::sequence_send_not_found(msg.source_port.clone(), msg.source_channel.clone())
})?;

//TODO: Application LOGIC.
Expand All @@ -47,8 +50,7 @@ where
timeout_timestamp: msg.timeout_timestamp,
};

let handler_output =
send_packet(ctx, packet).map_err(|e| Kind::HandlerRaisedError.context(e))?;
let handler_output = send_packet(ctx, packet).map_err(Error::ics04_channel)?;

//TODO: add event/atributes and writes to the store issued by the application logic for packet sending.
Ok(handler_output)
Expand Down
Loading