Skip to content

Fix errors parsing in querier #8

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

Merged
merged 1 commit into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/std/src/results/contract_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ use std::fmt;
/// assert_eq!(to_vec(&result).unwrap(), br#"{"error":"Something went wrong"}"#);
/// ```
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub enum ContractResult<S> {
pub enum ContractResult<S, E = String> {
Ok(S),
/// An error type that every custom error created by contract developers can be converted to.
/// This could potientially have more structure, but String is the easiest.
Err(String),
Err(E),
}

// Implementations here mimic the Result API and should be implemented via a conversion to Result
Expand Down
15 changes: 12 additions & 3 deletions packages/std/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{de::DeserializeOwned, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::marker::PhantomData;
use std::ops::Deref;

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

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]

pub enum LegacyQueryResult {
/// Whenever there is no specific error type available
GenericErr { msg: String },
}

/// A short-hand alias for the two-level query result (1. accessing the contract, 2. executing query in the contract)
pub type QuerierResult = SystemResult<ContractResult<Binary>>;
pub type QuerierResult = SystemResult<ContractResult<Binary, LegacyQueryResult>>;

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