MCPcopy Create free account
hub / github.com/consensus-shipyard/ipc / error_with_revert

Function error_with_revert

fendermint/eth/api/src/error.rs:82–106  ·  view source on GitHub ↗

Try to parse the data returned from the EVM as a revert string and append it to the message, so we have a bit more human readable feedback than just hexadecimal strings with the selector we can see in for example [here](https://github.com/gakonst/ethers-rs/commit/860100535812cbfe5e3cc417872392a6d76a159c). The goal is that if Solidity has something like `require(x > 0, "X must be positive")` then

(
    exit_code: ExitCode,
    msg: impl ToString,
    data: Option<impl AsRef<[u8]>>,
)

Source from the content-addressed store, hash-verified

80///
81/// The goal is that if Solidity has something like `require(x > 0, "X must be positive")` then we see the message in the JSON-RPC response.
82pub fn error_with_revert<T>(
83 exit_code: ExitCode,
84 msg: impl ToString,
85 data: Option<impl AsRef<[u8]>>,
86) -> Result<T, JsonRpcError> {
87 let msg = msg.to_string();
88 let (msg, data) = match data {
89 None => (msg, None),
90 Some(data) => {
91 // Try the simplest case of just a string, even though it's covered by the `SubnetActorErrors` as well.
92 // Then see if it's an error that one of our known IPC actor facets are producing.
93 let revert = if let Some(revert) = String::decode_with_selector(data.as_ref()) {
94 Some(revert)
95 } else {
96 SubnetActorErrors::decode_with_selector(data.as_ref()).map(|e| e.to_string())
97 };
98
99 (
100 revert.map(|rev| format!("{msg}\n{rev}")).unwrap_or(msg),
101 Some(hex::encode(data)),
102 )
103 }
104 };
105 error_with_data(exit_code, msg, data)
106}
107
108impl std::fmt::Display for JsonRpcError {
109 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

Callers 4

send_raw_transactionFunction · 0.85
callFunction · 0.85
estimate_gasFunction · 0.85
handle_typed_txnFunction · 0.85

Calls 3

error_with_dataFunction · 0.85
to_stringMethod · 0.80
as_refMethod · 0.45

Tested by

no test coverage detected