-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Certain JSON-RPC errors come with additional context. These additional data are now properly displayed.
- Loading branch information
1 parent
491eb81
commit 260ea7a
Showing
6 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::fmt::Display; | ||
|
||
use starknet::{ | ||
accounts::{AccountError, AccountFactoryError}, | ||
core::types::StarknetError, | ||
providers::ProviderError, | ||
}; | ||
|
||
/// Makes error details visible, as they're not displayed by default. | ||
pub fn account_error_mapper<S>(err: AccountError<S>) -> anyhow::Error | ||
where | ||
S: Display, | ||
{ | ||
match err { | ||
AccountError::Provider(ProviderError::StarknetError(err)) => map_starknet_error(err), | ||
err => anyhow::anyhow!("{}", err), | ||
} | ||
} | ||
|
||
/// Makes error details visible, as they're not displayed by default. | ||
pub fn account_factory_error_mapper<S>(err: AccountFactoryError<S>) -> anyhow::Error | ||
where | ||
S: Display, | ||
{ | ||
match err { | ||
AccountFactoryError::Provider(ProviderError::StarknetError(err)) => map_starknet_error(err), | ||
err => anyhow::anyhow!("{}", err), | ||
} | ||
} | ||
|
||
fn map_starknet_error(err: StarknetError) -> anyhow::Error { | ||
match err { | ||
StarknetError::ContractError(err) => { | ||
anyhow::anyhow!("ContractError: {}", err.revert_error.trim()) | ||
} | ||
StarknetError::TransactionExecutionError(err) => { | ||
anyhow::anyhow!( | ||
"TransactionExecutionError (tx index {}): {}", | ||
err.transaction_index, | ||
err.execution_error.trim() | ||
) | ||
} | ||
StarknetError::ValidationFailure(err) => { | ||
anyhow::anyhow!("ValidationFailure: {}", err.trim()) | ||
} | ||
StarknetError::UnexpectedError(err) => { | ||
anyhow::anyhow!("UnexpectedError: {}", err.trim()) | ||
} | ||
err => anyhow::anyhow!("{}", err), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ mod casm; | |
mod chain_id; | ||
mod compiler; | ||
mod decode; | ||
mod error; | ||
mod fee; | ||
mod network; | ||
mod path; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters