Skip to content

Commit

Permalink
Use thiserror, regenerate lockfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Apr 9, 2024
1 parent db219f6 commit ab6b92f
Show file tree
Hide file tree
Showing 25 changed files with 53 additions and 67 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/burner/Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/crypto-verify/Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/cyberpunk/Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/empty/Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/floaty/Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/hackatom/Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/ibc-reflect-send/Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/ibc-reflect/Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/queue/Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/reflect/Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/staking/Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/virus/Cargo.lock

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

3 changes: 2 additions & 1 deletion packages/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ schemars = { version = "0.8.16", optional = true }
serde = { version = "1.0.197", default-features = false, features = ["alloc", "derive"] }
sha2 = { version = "0.10.8", default-features = false }
static_assertions = "1.1.0"
thiserror = { version = "1.0.26", optional = true }

[features]
std = ["dep:schemars"]
std = ["dep:schemars", "dep:thiserror"]

[dev-dependencies]
# Cyclic dependencies for doc tests..
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ impl fmt::Display for CanonicalAddr {
}

#[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
pub enum Instantiate2AddressError {
/// Checksum must be 32 bytes
InvalidChecksumLength,
Expand All @@ -266,9 +267,6 @@ impl fmt::Display for Instantiate2AddressError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for Instantiate2AddressError {}

/// Creates a contract address using the predictable address format introduced with
/// wasmd 0.29. When using instantiate2, this is a way to precompute the address.
/// When using instantiate, the contract address will use a different algorithm and
Expand Down
51 changes: 14 additions & 37 deletions packages/core/src/errors/core_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::errors::{RecoverPubkeyError, VerificationError};
/// - Add enum case
/// - Add creator function in std_error_helpers.rs
#[derive(Display, Debug)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
pub enum CoreError {
#[display("Verification error: {source}")]
VerificationErr {
Expand Down Expand Up @@ -178,9 +179,6 @@ impl CoreError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for CoreError {}

impl PartialEq<CoreError> for CoreError {
fn eq(&self, rhs: &CoreError) -> bool {
match self {
Expand Down Expand Up @@ -421,6 +419,7 @@ impl fmt::Display for OverflowOperation {
}

#[derive(Display, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
#[display("Cannot {operation} with given operands")]
pub struct OverflowError {
pub operation: OverflowOperation,
Expand All @@ -432,16 +431,14 @@ impl OverflowError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for OverflowError {}

/// The error returned by [`TryFrom`] conversions that overflow, for example
/// when converting from [`Uint256`] to [`Uint128`].
///
/// [`TryFrom`]: core::convert::TryFrom
/// [`Uint256`]: crate::Uint256
/// [`Uint128`]: crate::Uint128
#[derive(Display, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
#[display("Error converting {source_type} to {target_type}")]
pub struct ConversionOverflowError {
pub source_type: &'static str,
Expand All @@ -457,10 +454,8 @@ impl ConversionOverflowError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for ConversionOverflowError {}

#[derive(Display, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
#[display("Cannot divide by zero")]
pub struct DivideByZeroError;

Expand All @@ -470,10 +465,8 @@ impl DivideByZeroError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for DivideByZeroError {}

#[derive(Display, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
pub enum DivisionError {
#[display("Divide by zero")]
DivideByZero,
Expand All @@ -482,10 +475,9 @@ pub enum DivisionError {
Overflow,
}

#[cfg(feature = "std")]
impl std::error::Error for DivisionError {}

#[derive(Display, Debug, From, PartialEq, Eq)]
#[derive(Display, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
#[cfg_attr(not(feature = "std"), derive(From))]
pub enum CheckedMultiplyFractionError {
#[display("{_0}")]
DivideByZero(#[from] DivideByZeroError),
Expand All @@ -497,10 +489,8 @@ pub enum CheckedMultiplyFractionError {
Overflow(#[from] OverflowError),
}

#[cfg(feature = "std")]
impl std::error::Error for CheckedMultiplyFractionError {}

#[derive(Display, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
pub enum CheckedMultiplyRatioError {
#[display("Denominator must not be zero")]
DivideByZero,
Expand All @@ -509,10 +499,8 @@ pub enum CheckedMultiplyRatioError {
Overflow,
}

#[cfg(feature = "std")]
impl std::error::Error for CheckedMultiplyRatioError {}

#[derive(Display, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
pub enum CheckedFromRatioError {
#[display("Denominator must not be zero")]
DivideByZero,
Expand All @@ -521,39 +509,31 @@ pub enum CheckedFromRatioError {
Overflow,
}

#[cfg(feature = "std")]
impl std::error::Error for CheckedFromRatioError {}

#[derive(Display, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
#[display("Round up operation failed because of overflow")]
pub struct RoundUpOverflowError;

#[cfg(feature = "std")]
impl std::error::Error for RoundUpOverflowError {}

#[derive(Display, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
#[display("Round down operation failed because of overflow")]
pub struct RoundDownOverflowError;

#[cfg(feature = "std")]
impl std::error::Error for RoundDownOverflowError {}

#[derive(Display, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
pub enum CoinsError {
#[display("Duplicate denom")]
DuplicateDenom,
}

#[cfg(feature = "std")]
impl std::error::Error for CoinsError {}

impl From<CoinsError> for CoreError {
fn from(value: CoinsError) -> Self {
Self::generic_err(format!("Creating Coins: {value}"))
}
}

#[derive(Display, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
pub enum CoinFromStrError {
#[display("Missing denominator")]
MissingDenom,
Expand All @@ -563,9 +543,6 @@ pub enum CoinFromStrError {
InvalidAmount(core::num::ParseIntError),
}

#[cfg(feature = "std")]
impl std::error::Error for CoinFromStrError {}

impl From<core::num::ParseIntError> for CoinFromStrError {
fn from(value: core::num::ParseIntError) -> Self {
Self::InvalidAmount(value)
Expand Down
Loading

0 comments on commit ab6b92f

Please sign in to comment.