From 1c2578ede462430d6d15e6c750a515600342f69d Mon Sep 17 00:00:00 2001 From: vms Date: Thu, 8 Oct 2020 11:41:00 +0300 Subject: [PATCH] update stepper errors --- Cargo.lock | 48 ++++++++++----------- aquamarine-vm/src/stepper_outcome.rs | 64 ++++++++++++++++++++-------- 2 files changed, 71 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f637cb4..e25920e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -693,15 +693,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "fluence" -version = "0.2.8" -source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" -dependencies = [ - "fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", - "fluence-sdk-main 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", -] - [[package]] name = "fluence" version = "0.2.8" @@ -712,6 +703,15 @@ dependencies = [ "fluence-sdk-main 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "fluence" +version = "0.2.8" +source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" +dependencies = [ + "fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", + "fluence-sdk-main 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", +] + [[package]] name = "fluence-app-service" version = "0.1.8" @@ -747,14 +747,6 @@ dependencies = [ "wasmer-wasi-fl", ] -[[package]] -name = "fluence-sdk-macro" -version = "0.2.8" -source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" -dependencies = [ - "fluence-sdk-wit 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", -] - [[package]] name = "fluence-sdk-macro" version = "0.2.8" @@ -765,13 +757,11 @@ dependencies = [ ] [[package]] -name = "fluence-sdk-main" +name = "fluence-sdk-macro" version = "0.2.8" source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" dependencies = [ - "fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", - "log", - "serde", + "fluence-sdk-wit 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", ] [[package]] @@ -786,9 +776,20 @@ dependencies = [ ] [[package]] -name = "fluence-sdk-wit" +name = "fluence-sdk-main" version = "0.2.8" source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" +dependencies = [ + "fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", + "log", + "serde", +] + +[[package]] +name = "fluence-sdk-wit" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560baf91197ded38a99a5c94ff366a3dd971ebf33f5d987ecce31d3dedf86d17" dependencies = [ "proc-macro2", "quote", @@ -801,8 +802,7 @@ dependencies = [ [[package]] name = "fluence-sdk-wit" version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560baf91197ded38a99a5c94ff366a3dd971ebf33f5d987ecce31d3dedf86d17" +source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" dependencies = [ "proc-macro2", "quote", diff --git a/aquamarine-vm/src/stepper_outcome.rs b/aquamarine-vm/src/stepper_outcome.rs index 9da771e9..601e899d 100644 --- a/aquamarine-vm/src/stepper_outcome.rs +++ b/aquamarine-vm/src/stepper_outcome.rs @@ -22,45 +22,63 @@ use crate::AquamarineVMError; use std::convert::TryFrom; use std::error::Error; -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Default, Clone, PartialEq, Eq)] pub(crate) struct RawStepperOutcome { pub ret_code: i32, pub data: String, pub next_peer_pks: Vec, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Default, Clone, PartialEq, Eq)] pub struct StepperOutcome { pub data: String, pub next_peer_pks: Vec, } -#[derive(Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum StepperError { /// Errors occurred while parsing aqua script in the form of S expressions. SExprParseError(String), /// Errors occurred while parsing supplied data. - DataParseError(String), + DataSerdeError(String), + + /// Errors occurred while parsing function arguments of an expression. + FuncArgsSerdeError(String), + + /// Errors occurred while parsing returned by call_service value. + CallServiceSerdeError(String), /// Indicates that environment variable with name CURRENT_PEER_ID isn't set. - CurrentPeerIdNotSet(String), + CurrentPeerIdEnvError(String), /// Semantic errors in instructions. InstructionError(String), - /// Semantic errors in instructions. + /// An error is occurred while calling local service via call_service. LocalServiceError(String), - /// Value with such name isn't presence in data. + /// Value for such name isn't presence in data. VariableNotFound(String), - /// Value with such path wasn't found in data. + /// Multiple values for such name found. + MultipleVariablesFound(String), + + /// Value with such path wasn't found in data with such error. VariableNotInJsonPath(String), + /// Value for such name isn't presence in data. + IncompatibleJValueType(String), + /// Multiple values found for such json path. MultipleValuesInJsonPath(String), + /// Fold state wasn't found for such iterator name. + FoldStateNotFound(String), + + /// Multiple fold states found for such iterator name. + MultipleFoldStates(String), + /// Related to such ret_code that doesn't have match with current StepperError. UnknownError(String), } @@ -71,13 +89,19 @@ impl std::fmt::Display for StepperError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { match self { StepperError::SExprParseError(err_msg) => write!(f, "{}", err_msg), - StepperError::DataParseError(err_msg) => write!(f, "{}", err_msg), - StepperError::CurrentPeerIdNotSet(err_msg) => write!(f, "{}", err_msg), + StepperError::DataSerdeError(err_msg) => write!(f, "{}", err_msg), + StepperError::FuncArgsSerdeError(err_msg) => write!(f, "{}", err_msg), + StepperError::CallServiceSerdeError(err_msg) => write!(f, "{}", err_msg), + StepperError::CurrentPeerIdEnvError(err_msg) => write!(f, "{}", err_msg), StepperError::InstructionError(err_msg) => write!(f, "{}", err_msg), StepperError::LocalServiceError(err_msg) => write!(f, "{}", err_msg), StepperError::VariableNotFound(err_msg) => write!(f, "{}", err_msg), + StepperError::MultipleVariablesFound(err_msg) => write!(f, "{}", err_msg), StepperError::VariableNotInJsonPath(err_msg) => write!(f, "{}", err_msg), + StepperError::IncompatibleJValueType(err_msg) => write!(f, "{}", err_msg), StepperError::MultipleValuesInJsonPath(err_msg) => write!(f, "{}", err_msg), + StepperError::FoldStateNotFound(err_msg) => write!(f, "{}", err_msg), + StepperError::MultipleFoldStates(err_msg) => write!(f, "{}", err_msg), StepperError::UnknownError(err_msg) => write!(f, "{}", err_msg), } } @@ -101,13 +125,19 @@ impl TryFrom for StepperOutcome { next_peer_pks: raw_outcome.next_peer_pks, }), 1 => to_vm_error!(SExprParseError), - 2 => to_vm_error!(DataParseError), - 3 => to_vm_error!(CurrentPeerIdNotSet), - 4 => to_vm_error!(InstructionError), - 5 => to_vm_error!(LocalServiceError), - 6 => to_vm_error!(VariableNotFound), - 7 => to_vm_error!(VariableNotInJsonPath), - 8 => to_vm_error!(MultipleValuesInJsonPath), + 2 => to_vm_error!(DataSerdeError), + 3 => to_vm_error!(FuncArgsSerdeError), + 4 => to_vm_error!(CallServiceSerdeError), + 5 => to_vm_error!(CurrentPeerIdEnvError), + 6 => to_vm_error!(InstructionError), + 7 => to_vm_error!(LocalServiceError), + 8 => to_vm_error!(VariableNotFound), + 9 => to_vm_error!(MultipleVariablesFound), + 10 => to_vm_error!(VariableNotInJsonPath), + 11 => to_vm_error!(IncompatibleJValueType), + 12 => to_vm_error!(MultipleValuesInJsonPath), + 13 => to_vm_error!(FoldStateNotFound), + 14 => to_vm_error!(MultipleFoldStates), _ => to_vm_error!(UnknownError), } }