Skip to content

Commit cca1c2f

Browse files
authored
Merge pull request #8 from scrtlabs/secret-fix-error
Fix errors parsing in querier
2 parents ca0cbb1 + 00dc8dd commit cca1c2f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/std/src/results/contract_result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ use std::fmt;
3030
/// assert_eq!(to_vec(&result).unwrap(), br#"{"error":"Something went wrong"}"#);
3131
/// ```
3232
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
33-
pub enum ContractResult<S> {
33+
pub enum ContractResult<S, E = String> {
3434
Ok(S),
3535
/// An error type that every custom error created by contract developers can be converted to.
3636
/// This could potientially have more structure, but String is the easiest.
37-
Err(String),
37+
Err(E),
3838
}
3939

4040
// Implementations here mimic the Result API and should be implemented via a conversion to Result

packages/std/src/traits.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use serde::{de::DeserializeOwned, Serialize};
1+
use serde::{de::DeserializeOwned, Deserialize, Serialize};
22
use std::marker::PhantomData;
33
use std::ops::Deref;
44

@@ -208,8 +208,17 @@ pub trait Api {
208208
fn ed25519_sign(&self, message: &[u8], private_key: &[u8]) -> Result<Vec<u8>, SigningError>;
209209
}
210210

211+
#[derive(Debug, Serialize, Deserialize, PartialEq)]
212+
#[serde(rename_all = "snake_case")]
213+
#[non_exhaustive]
214+
215+
pub enum LegacyQueryResult {
216+
/// Whenever there is no specific error type available
217+
GenericErr { msg: String },
218+
}
219+
211220
/// A short-hand alias for the two-level query result (1. accessing the contract, 2. executing query in the contract)
212-
pub type QuerierResult = SystemResult<ContractResult<Binary>>;
221+
pub type QuerierResult = SystemResult<ContractResult<Binary, LegacyQueryResult>>;
213222

214223
pub trait Querier {
215224
/// raw_query is all that must be implemented for the Querier.
@@ -265,7 +274,7 @@ impl<'a, C: CustomQuery> QuerierWrapper<'a, C> {
265274
system_err
266275
))),
267276
SystemResult::Ok(ContractResult::Err(contract_err)) => Err(StdError::generic_err(
268-
format!("Querier contract error: {}", contract_err),
277+
format!("Querier contract error: {:?}", contract_err),
269278
)),
270279
SystemResult::Ok(ContractResult::Ok(value)) => from_binary(&value),
271280
}

0 commit comments

Comments
 (0)