This commit is contained in:
Valery Antopol 2022-02-24 00:27:16 +03:00
parent 189a457dae
commit 536e4f365b
3 changed files with 20 additions and 18 deletions

View File

@ -18,9 +18,9 @@ use thiserror::Error;
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum ItJsonSerdeError { pub enum ItJsonSerdeError {
#[error("cannot serialize IValues to Json: {0}")] #[error("{0}")]
SerializationError(String), SerializationError(String),
#[error("cannot deserialize Json to IValues: {0}")] #[error("{0}")]
DeserializationError(String), DeserializationError(String),
} }

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
use it_json_serde::ItJsonSerdeError;
use marine::MError; use marine::MError;
use thiserror::Error; use thiserror::Error;
@ -54,19 +55,19 @@ pub enum FaaSError {
NoSuchModule(String), NoSuchModule(String),
/// Provided arguments aren't compatible with a called function signature. /// Provided arguments aren't compatible with a called function signature.
#[error(r#"arguments from json deserialization error in module "{module_name}", function "{function_name}": {message}"#)] #[error(r#"arguments from json deserialization error in module "{module_name}", function "{function_name}": {error}"#)]
JsonArgumentsDeserializationError { JsonArgumentsDeserializationError {
module_name: String, module_name: String,
function_name: String, function_name: String,
message: String, error: ItJsonSerdeError,
}, },
/// Returned outputs aren't compatible with a called function signature. /// Returned outputs aren't compatible with a called function signature.
#[error(r#"output to json serialization error in module "{module_name}", function "{function_name}": {message}"#)] #[error(r#"output to json serialization error in module "{module_name}", function "{function_name}": {error}"#)]
JsonOutputSerializationError { JsonOutputSerializationError {
module_name: String, module_name: String,
function_name: String, function_name: String,
message: String, error: ItJsonSerdeError,
}, },
/// Errors related to invalid config. /// Errors related to invalid config.
@ -103,18 +104,18 @@ impl From<std::convert::Infallible> for FaaSError {
macro_rules! json_to_faas_err { macro_rules! json_to_faas_err {
($json_expr:expr, $module_name:expr, $function_name:expr) => { ($json_expr:expr, $module_name:expr, $function_name:expr) => {
$json_expr.map_err(|e| match e { $json_expr.map_err(|e| match e {
it_json_serde::ItJsonSerdeError::SerializationError(message) => { it_json_serde::ItJsonSerdeError::SerializationError(_) => {
FaaSError::JsonOutputSerializationError { FaaSError::JsonOutputSerializationError {
module_name: $module_name, module_name: $module_name,
function_name: $function_name, function_name: $function_name,
message, error: e,
} }
} }
it_json_serde::ItJsonSerdeError::DeserializationError(message) => { it_json_serde::ItJsonSerdeError::DeserializationError(_) => {
FaaSError::JsonArgumentsDeserializationError { FaaSError::JsonArgumentsDeserializationError {
module_name: $module_name, module_name: $module_name,
function_name: $function_name, function_name: $function_name,
message, error: e,
} }
} }
}) })

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
use it_json_serde::ItJsonSerdeError;
use crate::MError; use crate::MError;
use thiserror::Error; use thiserror::Error;
@ -34,19 +35,19 @@ pub enum FaaSError {
NoSuchModule(String), NoSuchModule(String),
/// Provided arguments aren't compatible with a called function signature. /// Provided arguments aren't compatible with a called function signature.
#[error(r#"arguments from json deserialization error in module "{module_name}", function "{function_name}": {message}"#)] #[error(r#"arguments from json deserialization error in module "{module_name}", function "{function_name}": {error}"#)]
JsonArgumentsDeserializationError { JsonArgumentsDeserializationError {
module_name: String, module_name: String,
function_name: String, function_name: String,
message: String, error: ItJsonSerdeError,
}, },
/// Returned outputs aren't compatible with a called function signature. /// Returned outputs aren't compatible with a called function signature.
#[error(r#"output to json serialization error in module "{module_name}", function "{function_name}": {message}"#)] #[error(r#"output to json serialization error in module "{module_name}", function "{function_name}": {error}"#)]
JsonOutputSerializationError { JsonOutputSerializationError {
module_name: String, module_name: String,
function_name: String, function_name: String,
message: String, error: ItJsonSerdeError,
}, },
/// Errors related to invalid config. /// Errors related to invalid config.
@ -74,18 +75,18 @@ impl From<std::convert::Infallible> for FaaSError {
macro_rules! json_to_faas_err { macro_rules! json_to_faas_err {
($json_expr:expr, $module_name:expr, $function_name:expr) => { ($json_expr:expr, $module_name:expr, $function_name:expr) => {
$json_expr.map_err(|e| match e { $json_expr.map_err(|e| match e {
it_json_serde::ItJsonSerdeError::SerializationError(message) => { it_json_serde::ItJsonSerdeError::SerializationError(_) => {
FaaSError::JsonOutputSerializationError { FaaSError::JsonOutputSerializationError {
module_name: $module_name, module_name: $module_name,
function_name: $function_name, function_name: $function_name,
message, error: e,
} }
} }
it_json_serde::ItJsonSerdeError::DeserializationError(message) => { it_json_serde::ItJsonSerdeError::DeserializationError(_) => {
FaaSError::JsonArgumentsDeserializationError { FaaSError::JsonArgumentsDeserializationError {
module_name: $module_name, module_name: $module_name,
function_name: $function_name, function_name: $function_name,
message, error: e,
} }
} }
}) })