Skip to content

Commit

Permalink
feat: print error details on call
Browse files Browse the repository at this point in the history
A previous fix only surfaces error details on transaction-sending
commands. This commit adds support for the `call` command as well.
  • Loading branch information
xJonathanLEI committed Jan 28, 2024
1 parent 7919143 commit ccac7ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ where
}
}

/// Makes error details visible, as they're not displayed by default.
pub fn provider_error_mapper(err: ProviderError) -> anyhow::Error {
match err {
ProviderError::StarknetError(err) => map_starknet_error(err),
err => anyhow::anyhow!("{}", err),
}
}

fn map_starknet_error(err: StarknetError) -> anyhow::Error {
match err {
StarknetError::ContractError(err) => {
Expand Down
6 changes: 4 additions & 2 deletions src/subcommands/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use starknet::{
};

use crate::{
address_book::AddressBookResolver, decode::FeltDecoder, verbosity::VerbosityArgs, ProviderArgs,
address_book::AddressBookResolver, decode::FeltDecoder, error::provider_error_mapper,
verbosity::VerbosityArgs, ProviderArgs,
};

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -53,7 +54,8 @@ impl Call {
},
BlockId::Tag(BlockTag::Pending),
)
.await?;
.await
.map_err(provider_error_mapper)?;

if result.is_empty() {
println!("[]");
Expand Down

0 comments on commit ccac7ca

Please sign in to comment.