Skip to content

Commit

Permalink
chore: add error more detail information
Browse files Browse the repository at this point in the history
  • Loading branch information
hashableric committed Oct 18, 2023
1 parent 7abab20 commit 4dced27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions contracts/igps/core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use cosmwasm_std::{Coin, Uint256};

#[derive(thiserror::Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Expand All @@ -12,8 +14,11 @@ pub enum ContractError {
#[error("unauthorized")]
Unauthorized {},

#[error("insufficient funds")]
InsufficientFunds {},
#[error("insufficient funds: needed {gas_needed:?}, but only received {received:?}")]
InsufficientFunds {
received: Uint256,
gas_needed: Uint256,
},

#[error("gas oracle not found for {0}")]
GasOracleNotFound(u32),
Expand Down
8 changes: 7 additions & 1 deletion contracts/igps/core/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ pub fn pay_for_gas(
let gas_token = GAS_TOKEN.load(deps.storage)?;
let received = Uint256::from(cw_utils::must_pay(&info, &gas_token)?);
let gas_needed = quote_gas_price(deps.storage, &deps.querier, dest_domain, gas_amount)?;
ensure!(received >= gas_needed, ContractError::InsufficientFunds {});
ensure!(
received >= gas_needed,
ContractError::InsufficientFunds {
received,
gas_needed,
}
);

let payment_gap = Uint128::from_str(&(received - gas_needed).to_string())?;

Expand Down

0 comments on commit 4dced27

Please sign in to comment.