Skip to content

Commit 0fa82db

Browse files
authored
Merge pull request #82 from apollodao/dev/stderror-constructors
fix: Use StdError constructor functions
2 parents 886f137 + def6418 commit 0fa82db

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed

packages/osmosis-std-derive/src/lib.rs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn derive_cosmwasm_ext(input: TokenStream) -> TokenStream {
7777
type_url: Self::TYPE_URL.to_string(),
7878
value: self.to_proto_bytes(),
7979
}
80-
}
80+
}
8181
}
8282

8383
#query_request_conversion
@@ -102,20 +102,16 @@ pub fn derive_cosmwasm_ext(input: TokenStream) -> TokenStream {
102102

103103
fn try_from(binary: cosmwasm_std::Binary) -> Result<Self, Self::Error> {
104104
use ::prost::Message;
105-
#[cfg(feature = "backtraces")]
106-
use std::backtrace::Backtrace;
107105
Self::decode(&binary[..]).map_err(|e| {
108-
cosmwasm_std::StdError::ParseErr {
109-
target_type: stringify!(#ident).to_string(),
110-
msg: format!(
106+
cosmwasm_std::StdError::parse_err(
107+
stringify!(#ident),
108+
format!(
111109
"Unable to decode binary: \n - base64: {}\n - bytes array: {:?}\n\n{:?}",
112110
binary,
113111
binary.to_vec(),
114112
e
115-
),
116-
#[cfg(feature = "backtraces")]
117-
backtrace: Backtrace::capture(),
118-
}
113+
)
114+
)
119115
})
120116
}
121117
}
@@ -124,21 +120,11 @@ pub fn derive_cosmwasm_ext(input: TokenStream) -> TokenStream {
124120
type Error = cosmwasm_std::StdError;
125121

126122
fn try_from(result: cosmwasm_std::SubMsgResult) -> Result<Self, Self::Error> {
127-
#[cfg(feature = "backtraces")]
128-
use std::backtrace::Backtrace;
129123
result
130124
.into_result()
131-
.map_err(|e| cosmwasm_std::StdError::GenericErr {
132-
msg: e,
133-
#[cfg(feature = "backtraces")]
134-
backtrace: Backtrace::capture(),
135-
})?
125+
.map_err(|e| cosmwasm_std::StdError::generic_err(e))?
136126
.data
137-
.ok_or_else(|| cosmwasm_std::StdError::NotFound {
138-
kind: "cosmwasm_std::SubMsgResult::<T>".to_string(),
139-
#[cfg(feature = "backtraces")]
140-
backtrace: Backtrace::capture(),
141-
})?
127+
.ok_or_else(|| cosmwasm_std::StdError::not_found("cosmwasm_std::SubMsgResult::<T>"))?
142128
.try_into()
143129
}
144130
}

packages/osmosis-std/README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,12 @@ fn query_pool(
8585
) -> StdResult<osmosis_std::types::osmosis::gamm::v1beta1::Pool> {
8686
let res = GammQuerier::new(&deps.querier).pool(pool_id)?;
8787
res.pool
88-
.ok_or_else(|| StdError::NotFound {
89-
kind: "pool".to_string(),
90-
})?
88+
.ok_or_else(|| StdError::not_found("pool"))?
9189
.try_into() // convert `Any` to `osmosis_std::types::osmosis::gamm::v1beta1::Pool`
92-
.map_err(|e: DecodeError| StdError::ParseErr {
93-
target_type: "osmosis_std::types::osmosis::gamm::v1beta1::Pool".to_string(),
94-
msg: e.to_string(),
95-
})
90+
.map_err(|e: DecodeError| StdError::parse_err(
91+
"osmosis_std::types::osmosis::gamm::v1beta1::Pool",
92+
e
93+
))
9694
}
9795
```
9896

@@ -119,10 +117,10 @@ impl TryFrom<osmosis_std::shim::Any> for Pool {
119117
return Ok(Pool::StableSwap(pool));
120118
}
121119

122-
Err(StdError::ParseErr {
123-
target_type: "Pool".to_string(),
124-
msg: "Unmatched pool: must be either `Balancer` or `StableSwap`.".to_string(),
125-
})
120+
Err(StdError::parse_err(
121+
"Pool",
122+
"Unmatched pool: must be either `Balancer` or `StableSwap`."
123+
))
126124
}
127125
}
128126

@@ -132,9 +130,7 @@ fn query_pool(
132130
) -> StdResult<Pool> {
133131
let res = GammQuerier::new(&deps.querier).pool(pool_id)?;
134132
res.pool
135-
.ok_or_else(|| StdError::NotFound {
136-
kind: "pool".to_string(),
137-
})?
133+
.ok_or_else(|| StdError::not_found("pool"))?
138134
.try_into() // convert `Any` to `Pool`
139135
}
140136
```

0 commit comments

Comments
 (0)