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

Refactor error system #255

Merged
merged 44 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
969d65a
Redefine Ics20Error by displaydoc
DaviRain-Su Nov 22, 2022
99d8205
Redefine Ics02Error by displaydoc
DaviRain-Su Nov 22, 2022
0c73f95
Merge branch 'main' into use-displaydoc-as-error-handler
DaviRain-Su Nov 22, 2022
1b2fcc3
Update client_state.rs
DaviRain-Su Nov 22, 2022
a067a5e
Redefine Ics07Error by displaydoc
DaviRain-Su Nov 23, 2022
1af9128
Redefine Ics03Error by displaydoc
DaviRain-Su Nov 23, 2022
a2e7cbe
Redefine Ics04Error by displaydoc
DaviRain-Su Nov 23, 2022
d40612f
Redefine Ics05Error by displaydoc
DaviRain-Su Nov 23, 2022
fdbe14e
Redefine Ics23Error by displaydoc
DaviRain-Su Nov 23, 2022
34dbead
Redefine Ics24Error by displaydoc
DaviRain-Su Nov 23, 2022
c68bab8
Redefine Ics26Error by displaydoc
DaviRain-Su Nov 23, 2022
fcb198a
Redefine Ics18Error by displaydoc
DaviRain-Su Nov 23, 2022
42b9788
Redefine ParseFailure Error
DaviRain-Su Nov 23, 2022
0abb309
Redefine HeightError
DaviRain-Su Nov 23, 2022
5b9375c
Redefine ProofError
DaviRain-Su Nov 23, 2022
a11d007
Redefine SignerError
DaviRain-Su Nov 23, 2022
4d62320
Redefine TimestampOverflowError, ParseTimestampError
DaviRain-Su Nov 23, 2022
5cdfca1
Redefine event Error
DaviRain-Su Nov 23, 2022
2bcd1c9
update ics03Error
DaviRain-Su Nov 23, 2022
78d45e9
Update Ics04Error
DaviRain-Su Nov 23, 2022
2ca3b77
Update Ics26Error
DaviRain-Su Nov 23, 2022
070aea4
Remove flex-error
DaviRain-Su Nov 23, 2022
a6c2ccb
Update error.rs
DaviRain-Su Nov 23, 2022
d498573
Create 164-refactor-error-system.md
DaviRain-Su Nov 23, 2022
f0bf23b
Impl std::erorr::Error for IbcError
DaviRain-Su Nov 24, 2022
c1c0b58
Add #![allow(clippy::result_large_err)]
DaviRain-Su Nov 24, 2022
0da59db
Rename Ics02Error to ClientError
DaviRain-Su Nov 24, 2022
7cf2277
Rename Ics03Error to ConnectionError
DaviRain-Su Nov 24, 2022
77bed23
Disassembling out PacketError
DaviRain-Su Nov 24, 2022
d385798
Rename Ics04Error to ChannelError
DaviRain-Su Nov 24, 2022
1d6f64e
Rename Ics05Error to PortError
DaviRain-Su Nov 24, 2022
e3d2d33
Rename Ics23Error to CommitmentError
DaviRain-Su Nov 24, 2022
0979e1f
Rename Ics26Error to RouterError
DaviRain-Su Nov 24, 2022
29e2336
Rename Ics18Error to RelayerError
DaviRain-Su Nov 24, 2022
00ef217
Rename Ics20Error to TokenTransferError
DaviRain-Su Nov 24, 2022
686a298
Add ContextError for ValidationContext and ExecutionContext
DaviRain-Su Nov 24, 2022
995d429
Update RouterError
DaviRain-Su Nov 24, 2022
d4a6c4d
fix clippy
DaviRain-Su Nov 24, 2022
8628899
Update context.rs
DaviRain-Su Nov 25, 2022
1567a06
Update lib.rs
DaviRain-Su Nov 29, 2022
8912bde
Secondary error display output
DaviRain-Su Nov 29, 2022
8f2bbe7
Remove unused Error variant
DaviRain-Su Nov 29, 2022
2eeaff7
Remove unused Error variant
DaviRain-Su Nov 30, 2022
bba5a6d
Update 164-refactor-error-system.md
DaviRain-Su Nov 30, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Remove `flex-error` and remove unused error variants([#164](https://github.com/cosmos/ibc-rs/issues/164))
21 changes: 19 additions & 2 deletions crates/ibc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,24 @@ all-features = true

[features]
default = ["std"]
std = ["flex-error/std", "flex-error/eyre_tracer", "ibc-proto/std", "clock"]
std = [
"ibc-proto/std",
"ics23/std",
"serde/std",
"serde_json/std",
"erased-serde/std",
"tracing/std",
"prost/std",
"bytes/std",
"subtle-encoding/std",
"sha2/std",
"displaydoc/std",
"num-traits/std",
"uint/std",
"primitive-types/std",
"clock",
"tendermint/std",
]
clock = ["tendermint/clock", "time/std"]

# This feature grants access to development-time mocking libraries, such as `MockContext` or `MockHeader`.
Expand All @@ -40,7 +57,7 @@ bytes = { version = "1.2.1", default-features = false }
safe-regex = { version = "0.2.5", default-features = false }
subtle-encoding = { version = "0.5", default-features = false }
sha2 = { version = "0.10.6", default-features = false }
flex-error = { version = "0.4.4", default-features = false }
displaydoc = { version = "0.2", default-features = false }
num-traits = { version = "0.2.15", default-features = false }
derive_more = { version = "0.99.17", default-features = false, features = ["from", "into", "display"] }
uint = { version = "0.9", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions crates/ibc/src/applications/transfer/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::fmt::{Display, Error as FmtError, Formatter};

use serde::{Deserialize, Serialize};

use super::error::Error;
use super::error::TokenTransferError;
use crate::core::ics26_routing::context::Acknowledgement as AckTrait;
use crate::prelude::*;

Expand Down Expand Up @@ -36,7 +36,7 @@ impl Acknowledgement {
Self::Success(ConstAckSuccess::Success)
}

pub fn from_error(err: Error) -> Self {
pub fn from_error(err: TokenTransferError) -> Self {
Self::Error(format!("{}: {}", ACK_ERR_STR, err))
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/ibc/src/applications/transfer/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::str::FromStr;
use derive_more::{Display, From, Into};
use serde::{Deserialize, Serialize};

use super::error::Error;
use super::error::TokenTransferError;
use crate::bigint::U256;

/// A type for representing token transfer amounts.
Expand All @@ -22,10 +22,10 @@ impl Amount {
}

impl FromStr for Amount {
type Err = Error;
type Err = TokenTransferError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let amount = U256::from_dec_str(s).map_err(Error::invalid_amount)?;
let amount = U256::from_dec_str(s).map_err(TokenTransferError::InvalidAmount)?;
Ok(Self(amount))
}
}
Expand Down
34 changes: 19 additions & 15 deletions crates/ibc/src/applications/transfer/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};

use super::amount::Amount;
use super::denom::{BaseDenom, PrefixedDenom};
use super::error::Error;
use super::error::TokenTransferError;
use crate::prelude::*;
use crate::serializers::serde_string;

Expand All @@ -30,35 +30,39 @@ pub struct Coin<D> {

impl<D: FromStr> Coin<D>
where
D::Err: Into<Error>,
D::Err: Into<TokenTransferError>,
{
pub fn from_string_list(coin_str: &str) -> Result<Vec<Self>, Error> {
pub fn from_string_list(coin_str: &str) -> Result<Vec<Self>, TokenTransferError> {
coin_str.split(',').map(FromStr::from_str).collect()
}
}

impl<D: FromStr> FromStr for Coin<D>
where
D::Err: Into<Error>,
D::Err: Into<TokenTransferError>,
{
type Err = Error;
type Err = TokenTransferError;

#[allow(clippy::assign_op_pattern)]
fn from_str(coin_str: &str) -> Result<Self, Error> {
fn from_str(coin_str: &str) -> Result<Self, TokenTransferError> {
// Denominations can be 3 ~ 128 characters long and support letters, followed by either
// a letter, a number or a separator ('/', ':', '.', '_' or '-').
// Loosely copy the regex from here:
// https://github.com/cosmos/cosmos-sdk/blob/v0.45.5/types/coin.go#L760-L762
let matcher = regex!(br"([0-9]+)([a-zA-Z0-9/:\\._\x2d]+)");

let (m1, m2) = matcher
.match_slices(coin_str.as_bytes())
.ok_or_else(|| Error::invalid_coin(coin_str.to_string()))?;
let (m1, m2) = matcher.match_slices(coin_str.as_bytes()).ok_or_else(|| {
TokenTransferError::InvalidCoin {
coin: coin_str.to_string(),
}
})?;

let amount = from_utf8(m1).map_err(Error::utf8_decode)?.parse()?;
let amount = from_utf8(m1)
.map_err(TokenTransferError::Utf8Decode)?
.parse()?;

let denom = from_utf8(m2)
.map_err(Error::utf8_decode)?
.map_err(TokenTransferError::Utf8Decode)?
.parse()
.map_err(Into::into)?;

Expand All @@ -68,9 +72,9 @@ where

impl<D: FromStr> TryFrom<ProtoCoin> for Coin<D>
where
D::Err: Into<Error>,
D::Err: Into<TokenTransferError>,
{
type Error = Error;
type Error = TokenTransferError;

fn try_from(proto: ProtoCoin) -> Result<Coin<D>, Self::Error> {
let denom = D::from_str(&proto.denom).map_err(Into::into)?;
Expand Down Expand Up @@ -108,7 +112,7 @@ mod tests {
use super::*;

#[test]
fn test_parse_raw_coin() -> Result<(), Error> {
fn test_parse_raw_coin() -> Result<(), TokenTransferError> {
{
let coin = RawCoin::from_str("123stake")?;
assert_eq!(coin.denom, "stake");
Expand Down Expand Up @@ -137,7 +141,7 @@ mod tests {
}

#[test]
fn test_parse_raw_coin_list() -> Result<(), Error> {
fn test_parse_raw_coin_list() -> Result<(), TokenTransferError> {
{
let coins = RawCoin::from_string_list("123stake,1a1,999den0m")?;
assert_eq!(coins.len(), 3);
Expand Down
Loading