Skip to content

Commit

Permalink
fix: use RouterError in case of ModuleID not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhad-Shabani committed Sep 23, 2024
1 parent 0642d4a commit 9045377
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
17 changes: 8 additions & 9 deletions ibc-core/ics25-handler/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use ibc_core_channel::handler::{
chan_open_try_execute, chan_open_try_validate, recv_packet_execute, recv_packet_validate,
timeout_packet_execute, timeout_packet_validate, TimeoutMsgType,
};
use ibc_core_channel::types::error::ChannelError;
use ibc_core_channel::types::msgs::{
channel_msg_to_port_id, packet_msg_to_port_id, ChannelMsg, PacketMsg,
};
Expand Down Expand Up @@ -80,8 +79,8 @@ where
},
MsgEnvelope::Channel(msg) => {
let port_id = channel_msg_to_port_id(&msg);
let module_id = router.lookup_module(port_id).ok_or(ChannelError::Host(
HostError::missing_state(format!("failed to look up port {}", port_id.clone())),
let module_id = router.lookup_module(port_id).ok_or(RouterError::Host(
HostError::missing_state(format!("missing module ID for port {}", port_id.clone())),
))?;
let module = router
.get_route(&module_id)
Expand All @@ -98,8 +97,8 @@ where
}
MsgEnvelope::Packet(msg) => {
let port_id = packet_msg_to_port_id(&msg);
let module_id = router.lookup_module(port_id).ok_or(ChannelError::Host(
HostError::missing_state(format!("failed to look up port {}", port_id.clone())),
let module_id = router.lookup_module(port_id).ok_or(RouterError::Host(
HostError::missing_state(format!("missing module ID for port {}", port_id.clone())),
))?;
let module = router
.get_route(&module_id)
Expand Down Expand Up @@ -154,8 +153,8 @@ where
},
MsgEnvelope::Channel(msg) => {
let port_id = channel_msg_to_port_id(&msg);
let module_id = router.lookup_module(port_id).ok_or(ChannelError::Host(
HostError::missing_state(format!("failed to look up port {}", port_id.clone())),
let module_id = router.lookup_module(port_id).ok_or(RouterError::Host(
HostError::missing_state(format!("missing module ID for port {}", port_id.clone())),
))?;
let module = router
.get_route_mut(&module_id)
Expand All @@ -172,8 +171,8 @@ where
}
MsgEnvelope::Packet(msg) => {
let port_id = packet_msg_to_port_id(&msg);
let module_id = router.lookup_module(port_id).ok_or(ChannelError::Host(
HostError::missing_state(format!("failed to look up port {}", port_id.clone())),
let module_id = router.lookup_module(port_id).ok_or(RouterError::Host(
HostError::missing_state(format!("missing module ID for port {}", port_id.clone())),
))?;
let module = router
.get_route_mut(&module_id)
Expand Down
3 changes: 3 additions & 0 deletions ibc-core/ics26-routing/types/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use displaydoc::Display;
use ibc_core_host_types::error::HostError;
use ibc_primitives::prelude::*;

/// Error type for the router module.
#[derive(Debug, Display, derive_more::From)]

Check warning on line 6 in ibc-core/ics26-routing/types/src/error.rs

View check run for this annotation

Codecov / codecov/patch

ibc-core/ics26-routing/types/src/error.rs#L6

Added line #L6 was not covered by tests
pub enum RouterError {
/// host error: {0}
Host(HostError),
/// missing module
MissingModule,
}
Expand Down

0 comments on commit 9045377

Please sign in to comment.