Skip to content

Commit

Permalink
better error handling for sdk query in client
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Aug 29, 2024
1 parent 526c261 commit f57a1a9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,11 +1183,8 @@ pub async fn query_total_supply<N: Namada>(
args: args::QueryTotalSupply,
) {
let token = args.token;
let supply = unwrap_client_response::<N::Client, token::Amount>(
RPC.vp()
.token()
.total_supply(context.client(), &token)
.await,
let supply = unwrap_sdk_result(
rpc::get_token_total_supply(context.client(), &token).await,
);
let amount_str = format_denominated_amount(
context.client(),
Expand Down Expand Up @@ -2046,6 +2043,14 @@ fn unwrap_client_response<C: namada_sdk::queries::Client, T>(
})
}

/// A helper to unwrap an SDK query result. Will shut down process on error.
fn unwrap_sdk_result<T>(response: Result<T, namada_sdk::error::Error>) -> T {
response.unwrap_or_else(|err| {
eprintln!("Error in the query: {:?}", err);
cli::safe_exit(1)
})
}

pub async fn compute_proposal_votes<C: namada_sdk::queries::Client + Sync>(
client: &C,
proposal_id: u64,
Expand Down

0 comments on commit f57a1a9

Please sign in to comment.