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]>>,
)
| 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. |
| 82 | pub 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 | |
| 108 | impl std::fmt::Display for JsonRpcError { |
| 109 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
no test coverage detected