Skip to content

Commit

Permalink
Merge pull request #80 from CosmWasm/refactoring-errors
Browse files Browse the repository at this point in the history
Refactoring errors
  • Loading branch information
DariuszDepta authored Oct 9, 2023
2 parents 3a4ae45 + 988bc20 commit 34a2c9d
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 45 deletions.
34 changes: 17 additions & 17 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ cosmwasm_1_3 = ["cosmwasm_1_2", "cosmwasm-std/cosmwasm_1_3"]
cosmwasm_1_4 = ["cosmwasm_1_3", "cosmwasm-std/cosmwasm_1_4"]

[dependencies]
cw-utils = "1.0.1"
cw-utils = "1.0.2"
cw-storage-plus = "1.1.0"
cosmwasm-std = { version = "1.4.0", features = ["staking", "stargate"] }
itertools = "0.11.0"
schemars = "0.8.13"
schemars = "0.8.15"
serde = { version = "1.0.188", default-features = false, features = ["derive"] }
prost = "0.12.0"
prost = "0.12.1"
anyhow = "1.0.75"
thiserror = "1.0.48"
thiserror = "1.0.49"
derivative = "2.2.0"
sha2 = "0.10.7"
sha2 = "0.10.8"

[dev-dependencies]
once_cell = "1.18.0"
Expand Down
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::bank::{Bank, BankKeeper, BankSudo};
use crate::contracts::Contract;
use crate::error::{bail, AnyResult};
use crate::executor::{AppResponse, Executor};
use crate::gov::Gov;
use crate::ibc::Ibc;
Expand All @@ -8,7 +9,6 @@ use crate::staking::{Distribution, DistributionKeeper, StakeKeeper, Staking, Sta
use crate::transactions::transactional;
use crate::wasm::{ContractData, Wasm, WasmKeeper, WasmSudo};
use crate::AppBuilder;
use anyhow::{bail, Result as AnyResult};
use cosmwasm_std::testing::{MockApi, MockStorage};
use cosmwasm_std::{
from_slice, to_binary, Addr, Api, Binary, BlockInfo, ContractResult, CosmosMsg, CustomQuery,
Expand Down
2 changes: 1 addition & 1 deletion src/bank.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::app::CosmosRouter;
use crate::error::{bail, AnyResult};
use crate::executor::AppResponse;
use crate::module::Module;
use crate::prefixed_storage::{prefixed, prefixed_read};
use anyhow::{bail, Result as AnyResult};
use cosmwasm_std::{
coin, to_binary, Addr, AllBalanceResponse, Api, BalanceResponse, BankMsg, BankQuery, Binary,
BlockInfo, Coin, Event, Order, Querier, StdResult, Storage, SupplyResponse, Uint128,
Expand Down
8 changes: 4 additions & 4 deletions src/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, bail, Result as AnyResult};
use crate::error::{anyhow, bail, AnyError, AnyResult};
use cosmwasm_std::{
from_slice, Binary, CosmosMsg, CustomQuery, Deps, DepsMut, Empty, Env, MessageInfo,
QuerierWrapper, Reply, Response, SubMsg,
Expand Down Expand Up @@ -64,10 +64,10 @@ pub struct ContractWrapper<
C = Empty,
Q = Empty,
T4 = Empty,
E4 = anyhow::Error,
E5 = anyhow::Error,
E4 = AnyError,
E5 = AnyError,
T6 = Empty,
E6 = anyhow::Error,
E6 = AnyError,
> where
T1: DeserializeOwned + Debug,
T2: DeserializeOwned,
Expand Down
2 changes: 1 addition & 1 deletion src/custom_handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::app::CosmosRouter;
use crate::error::{bail, AnyResult};
use crate::{AppResponse, Module};
use anyhow::{bail, Result as AnyResult};
use cosmwasm_std::{Addr, Api, Binary, BlockInfo, Empty, Querier, Storage};
use derivative::Derivative;
use std::cell::{Ref, RefCell};
Expand Down
1 change: 1 addition & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub use anyhow::{anyhow, bail, Context as AnyContext, Error as AnyError, Result as AnyResult};
use cosmwasm_std::{WasmMsg, WasmQuery};
use thiserror::Error;

Expand Down
2 changes: 1 addition & 1 deletion src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::Result as AnyResult;
use crate::error::AnyResult;
use cosmwasm_std::{
to_binary, Addr, Attribute, BankMsg, Binary, Coin, CosmosMsg, Event, SubMsgResponse, WasmMsg,
};
Expand Down
7 changes: 4 additions & 3 deletions src/ibc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::error::AnyResult;
use crate::{AppResponse, FailingModule, Module};
use cosmwasm_std::{Binary, Empty, IbcMsg, IbcQuery};

Expand All @@ -20,7 +21,7 @@ impl Module for IbcAcceptingModule {
_block: &cosmwasm_std::BlockInfo,
_sender: cosmwasm_std::Addr,
_msg: Self::ExecT,
) -> anyhow::Result<AppResponse>
) -> AnyResult<AppResponse>
where
ExecC: std::fmt::Debug
+ Clone
Expand All @@ -40,7 +41,7 @@ impl Module for IbcAcceptingModule {
_router: &dyn crate::CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
_block: &cosmwasm_std::BlockInfo,
_msg: Self::SudoT,
) -> anyhow::Result<AppResponse>
) -> AnyResult<AppResponse>
where
ExecC: std::fmt::Debug
+ Clone
Expand All @@ -60,7 +61,7 @@ impl Module for IbcAcceptingModule {
_querier: &dyn cosmwasm_std::Querier,
_block: &cosmwasm_std::BlockInfo,
_request: Self::QueryT,
) -> anyhow::Result<Binary> {
) -> AnyResult<Binary> {
Ok(Binary::default())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/module.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::app::CosmosRouter;
use crate::error::{bail, AnyResult};
use crate::AppResponse;
use anyhow::{bail, Result as AnyResult};
use cosmwasm_std::{Addr, Api, Binary, BlockInfo, CustomQuery, Querier, Storage};
use schemars::JsonSchema;
use serde::de::DeserializeOwned;
Expand Down
2 changes: 1 addition & 1 deletion src/staking.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::app::CosmosRouter;
use crate::error::{anyhow, bail, AnyResult};
use crate::executor::AppResponse;
use crate::prefixed_storage::{prefixed, prefixed_read};
use crate::{BankSudo, Module};
use anyhow::{anyhow, bail, Result as AnyResult};
use cosmwasm_std::{
coin, ensure, ensure_eq, to_binary, Addr, AllDelegationsResponse, AllValidatorsResponse, Api,
BankMsg, Binary, BlockInfo, BondedDenomResponse, Coin, CustomQuery, Decimal, Delegation,
Expand Down
2 changes: 1 addition & 1 deletion src/tests/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::app::no_init;
use crate::custom_handler::CachingCustomHandler;
use crate::error::{bail, AnyResult};
use crate::test_helpers::echo::EXECUTE_REPLY_BASE_ID;
use crate::test_helpers::{caller, echo, error, hackatom, payout, reflect, CustomMsg};
use crate::transactions::{transactional, StorageTransaction};
Expand All @@ -8,7 +9,6 @@ use crate::{
custom_app, next_block, App, AppResponse, Bank, CosmosRouter, Distribution, Executor, Module,
Router, Staking, Wasm, WasmSudo,
};
use anyhow::{bail, Result as AnyResult};
use cosmwasm_std::testing::{mock_env, MockApi, MockQuerier};
use cosmwasm_std::{
coin, coins, from_slice, to_binary, Addr, AllBalanceResponse, Api, Attribute, BankMsg,
Expand Down
7 changes: 4 additions & 3 deletions src/tests/gov.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::error::AnyResult;
use crate::test_helpers::{stargate, stargate::ExecMsg};
use crate::{App, AppBuilder, AppResponse, CosmosRouter, Executor, Gov, Module};
use cosmwasm_std::{Addr, Api, Binary, BlockInfo, Empty, GovMsg, Querier, Storage};
Expand All @@ -17,7 +18,7 @@ impl Module for AcceptingModule {
_block: &BlockInfo,
_sender: Addr,
_msg: Self::ExecT,
) -> anyhow::Result<AppResponse>
) -> AnyResult<AppResponse>
where
ExecC: std::fmt::Debug
+ Clone
Expand All @@ -37,7 +38,7 @@ impl Module for AcceptingModule {
_router: &dyn CosmosRouter<ExecC = ExecC, QueryC = QueryC>,
_block: &BlockInfo,
_msg: Self::SudoT,
) -> anyhow::Result<AppResponse>
) -> AnyResult<AppResponse>
where
ExecC: std::fmt::Debug
+ Clone
Expand All @@ -57,7 +58,7 @@ impl Module for AcceptingModule {
_querier: &dyn Querier,
_block: &BlockInfo,
_request: Self::QueryT,
) -> anyhow::Result<Binary> {
) -> AnyResult<Binary> {
Ok(Binary::default())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::Result as AnyResult;
use crate::error::AnyResult;
use cosmwasm_std::Storage;
#[cfg(feature = "iterator")]
use cosmwasm_std::{Order, Record};
Expand Down
5 changes: 2 additions & 3 deletions src/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::app::{CosmosRouter, RouterQuerier};
use crate::contracts::Contract;
use crate::error::Error;
use crate::error::{bail, AnyContext, AnyError, AnyResult, Error};
use crate::executor::AppResponse;
use crate::prefixed_storage::{prefixed, prefixed_read, PrefixedStorage, ReadonlyPrefixedStorage};
use crate::transactions::transactional;
use anyhow::{bail, Context, Result as AnyResult};
use cosmwasm_std::testing::mock_wasmd_attr;
use cosmwasm_std::{
to_binary, Addr, Api, Attribute, BankMsg, Binary, BlockInfo, Coin, ContractInfo,
Expand Down Expand Up @@ -811,7 +810,7 @@ where
let sub_res =
self.execute_submsg(api, router, storage, block, contract.clone(), resend)?;
events.extend_from_slice(&sub_res.events);
Ok::<_, anyhow::Error>(sub_res.data.or(data))
Ok::<_, AnyError>(sub_res.data.or(data))
})?;

Ok(AppResponse { events, data })
Expand Down
2 changes: 1 addition & 1 deletion tests/app_builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{bail, Result as AnyResult};
use cosmwasm_std::{Addr, Api, Binary, BlockInfo, CustomQuery, Querier, Storage};
use cw_multi_test::error::{bail, AnyResult};
use cw_multi_test::{AppResponse, CosmosRouter, Module};
use cw_storage_plus::Item;
use schemars::JsonSchema;
Expand Down
2 changes: 1 addition & 1 deletion tests/app_builder/with_wasm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::app_builder::{contracts, MyKeeper};
use anyhow::{bail, Result as AnyResult};
use cosmwasm_std::{
Addr, Api, Binary, BlockInfo, Empty, Querier, Record, Storage, WasmMsg, WasmQuery,
};
use cw_multi_test::error::{bail, AnyResult};
use cw_multi_test::{
AppBuilder, AppResponse, Contract, ContractData, CosmosRouter, Executor, Wasm, WasmKeeper,
WasmSudo,
Expand Down

0 comments on commit 34a2c9d

Please sign in to comment.