diff --git a/crates/common/src/error.rs b/crates/common/src/error.rs index 4f7486160..869eb718a 100644 --- a/crates/common/src/error.rs +++ b/crates/common/src/error.rs @@ -42,18 +42,22 @@ pub enum AbiDecodedErrorType { impl From for String { fn from(value: AbiDecodedErrorType) -> Self { - match value { - AbiDecodedErrorType::Unknown => "native parser panicked with unknown error!".to_owned(), - AbiDecodedErrorType::Known { name, args, .. } => { - format!("native parser panicked with: {}\n{}", name, args.join("\n")) - } - } + value.to_string() } } impl std::fmt::Display for AbiDecodedErrorType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", std::convert::Into::::into(self.clone())) + match self { + AbiDecodedErrorType::Unknown => { + f.write_str("native parser panicked with unknown error!") + } + AbiDecodedErrorType::Known { name, args, .. } => f.write_str(&format!( + "native parser panicked with: {}\n{}", + name, + args.join("\n") + )), + } } } @@ -166,23 +170,23 @@ impl<'a> From>>> for ForkC } #[derive(Debug, Error)] -pub enum ForkParseError<'a> { +pub enum ForkParseError { #[error("ForkCall error: {0}")] - ForkCallFailed(ForkCallError<'a>), + ForkCallFailed(ForkCallError<'static>), #[error("{0}")] AbiDecodedError(AbiDecodedErrorType), #[error("Invalid Front Matter error: {0}")] InvalidFrontMatter(#[from] AddOrderArgsError), } -impl<'a> From for ForkParseError<'a> { +impl From for ForkParseError { fn from(value: AbiDecodedErrorType) -> Self { Self::AbiDecodedError(value) } } -impl<'a> From> for ForkParseError<'a> { - fn from(value: ForkCallError<'a>) -> Self { +impl From> for ForkParseError { + fn from(value: ForkCallError<'static>) -> Self { Self::ForkCallFailed(value) } } diff --git a/crates/common/src/fork.rs b/crates/common/src/fork.rs index 01a8d5a18..e936c902c 100644 --- a/crates/common/src/fork.rs +++ b/crates/common/src/fork.rs @@ -66,12 +66,12 @@ pub async fn fork_call<'a>( /// checks the front matter validity and parses the given rainlang string /// with the deployer parsed from the front matter /// returns abi encoded expression config on Ok variant -pub async fn fork_parse_rainlang<'a>( +pub async fn fork_parse_rainlang( rainlang_string: &str, front_matter: &str, fork_url: &str, fork_block_number: u64, -) -> Result> { +) -> Result { let deployer = AddOrderArgs::try_parse_frontmatter(front_matter)?.0; let calldata = iParserCall {}.abi_encode(); diff --git a/tauri-app/src-tauri/src/commands/fork.rs b/tauri-app/src-tauri/src/commands/fork.rs index fb978e548..b8b39a76a 100644 --- a/tauri-app/src-tauri/src/commands/fork.rs +++ b/tauri-app/src-tauri/src/commands/fork.rs @@ -1,15 +1,17 @@ +use super::super::error::CommandError; use alloy_primitives::bytes::Bytes; use rain_orderbook_common::fork::fork_parse_rainlang; #[tauri::command] -pub async fn fork_parse<'a>( +pub async fn fork_parse( rainlang: &str, front_matter: &str, fork_url: &str, fork_block_number: u64, -) -> Result { - fork_parse_rainlang(rainlang, front_matter, fork_url, fork_block_number) - .await - .map(Bytes::from) - .map_err(|e| e.to_string()) +) -> Result { + Ok( + fork_parse_rainlang(rainlang, front_matter, fork_url, fork_block_number) + .await + .map(Bytes::from)?, + ) } diff --git a/tauri-app/src-tauri/src/error.rs b/tauri-app/src-tauri/src/error.rs index eb3e202cb..9b8e5b110 100644 --- a/tauri-app/src-tauri/src/error.rs +++ b/tauri-app/src-tauri/src/error.rs @@ -1,5 +1,6 @@ use alloy_ethers_typecast::{client::LedgerClientError, transaction::ReadableClientError}; use alloy_primitives::ruint::FromUintError; +use rain_orderbook_common::error::ForkParseError; use rain_orderbook_subgraph_client::{OrderbookSubgraphClientError, WriteCsvError}; use serde::{ser::Serializer, Serialize}; use thiserror::Error; @@ -24,6 +25,9 @@ pub enum CommandError { #[error(transparent)] WriteCsvError(#[from] WriteCsvError), + + #[error(transparent)] + ForkParseRainlangError(ForkParseError), } impl Serialize for CommandError { @@ -36,3 +40,9 @@ impl Serialize for CommandError { } pub type CommandResult = Result; + +impl From for CommandError { + fn from(value: ForkParseError) -> Self { + Self::ForkParseRainlangError(value) + } +}