2020-06-05 20:12:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Fluence Labs Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use fce::FCEError;
|
|
|
|
|
2020-09-15 22:14:15 +00:00
|
|
|
use serde_json::error::Error as SerdeError;
|
|
|
|
|
2020-06-06 18:34:13 +00:00
|
|
|
use std::io::Error as IOError;
|
2020-06-05 20:12:02 +00:00
|
|
|
use std::error::Error;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2020-06-15 14:22:18 +00:00
|
|
|
pub enum FaaSError {
|
2020-06-06 18:34:13 +00:00
|
|
|
/// An error related to config parsing.
|
|
|
|
ConfigParseError(String),
|
|
|
|
|
2020-08-07 21:52:21 +00:00
|
|
|
/// An error occurred at the instantiation step.
|
|
|
|
InstantiationError(String),
|
|
|
|
|
2020-06-11 16:11:34 +00:00
|
|
|
/// Various errors related to file i/o.
|
2020-06-06 18:34:13 +00:00
|
|
|
IOError(String),
|
2020-06-05 20:12:02 +00:00
|
|
|
|
2020-09-15 22:14:15 +00:00
|
|
|
/// A function with specified name is missing.
|
|
|
|
MissingFunctionError(String),
|
|
|
|
|
|
|
|
/// An argument with specified name is missing.
|
|
|
|
MissingArgumentError(String),
|
|
|
|
|
2020-10-21 19:21:16 +00:00
|
|
|
/// Returns when there is no module with such name.
|
|
|
|
NoSuchModule(String),
|
|
|
|
|
2020-09-15 22:14:15 +00:00
|
|
|
/// Not enough arguments provided for FCE call.
|
|
|
|
JsonArgumentsDeserializationError(String),
|
|
|
|
|
|
|
|
/// An error occurred when incorrect json argument is supplied.
|
|
|
|
ArgumentDeserializationError(SerdeError),
|
|
|
|
|
2020-06-16 11:20:33 +00:00
|
|
|
/// FCE errors.
|
2020-06-15 14:22:18 +00:00
|
|
|
EngineError(FCEError),
|
2020-10-01 09:19:38 +00:00
|
|
|
|
|
|
|
ParseConfigError(toml::de::Error),
|
2020-06-05 20:12:02 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 14:22:18 +00:00
|
|
|
impl Error for FaaSError {}
|
2020-06-05 20:12:02 +00:00
|
|
|
|
2020-06-15 14:22:18 +00:00
|
|
|
impl std::fmt::Display for FaaSError {
|
2020-06-05 20:12:02 +00:00
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
|
|
|
match self {
|
2020-06-15 14:22:18 +00:00
|
|
|
FaaSError::ConfigParseError(err_msg) => write!(f, "{}", err_msg),
|
2020-08-07 21:52:21 +00:00
|
|
|
FaaSError::InstantiationError(err_msg) => write!(f, "{}", err_msg),
|
2020-09-15 22:14:15 +00:00
|
|
|
FaaSError::MissingFunctionError(func_name) => {
|
|
|
|
write!(f, "function with name `{}` is missing", func_name)
|
|
|
|
}
|
|
|
|
FaaSError::MissingArgumentError(arg_name) => {
|
2020-10-21 19:21:16 +00:00
|
|
|
write!(f, r#"argument with name "{}" is missing"#, arg_name)
|
|
|
|
}
|
|
|
|
FaaSError::NoSuchModule(module_name) => {
|
|
|
|
write!(f, r#"module with name "{}" is missing"#, module_name)
|
2020-09-15 22:14:15 +00:00
|
|
|
}
|
|
|
|
FaaSError::JsonArgumentsDeserializationError(args) => write!(f, "{}", args),
|
|
|
|
FaaSError::ArgumentDeserializationError(err_msg) => write!(f, "{:?}", err_msg),
|
2020-06-15 14:22:18 +00:00
|
|
|
FaaSError::IOError(err_msg) => write!(f, "{}", err_msg),
|
|
|
|
FaaSError::EngineError(err) => write!(f, "{}", err),
|
2020-10-01 09:19:38 +00:00
|
|
|
FaaSError::ParseConfigError(err) => write!(f, "{}", err),
|
2020-06-05 20:12:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:22:18 +00:00
|
|
|
impl From<IOError> for FaaSError {
|
2020-06-05 20:12:02 +00:00
|
|
|
fn from(err: IOError) -> Self {
|
2020-06-15 14:22:18 +00:00
|
|
|
FaaSError::IOError(format!("{}", err))
|
2020-06-05 20:12:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:22:18 +00:00
|
|
|
impl From<FCEError> for FaaSError {
|
2020-06-05 20:12:02 +00:00
|
|
|
fn from(err: FCEError) -> Self {
|
2020-06-15 14:22:18 +00:00
|
|
|
FaaSError::EngineError(err)
|
2020-06-05 20:12:02 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-30 12:57:48 +00:00
|
|
|
|
|
|
|
impl From<toml::de::Error> for FaaSError {
|
|
|
|
fn from(err: toml::de::Error) -> Self {
|
|
|
|
FaaSError::ConfigParseError(format!("{}", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::convert::Infallible> for FaaSError {
|
2020-08-07 20:24:28 +00:00
|
|
|
fn from(_: std::convert::Infallible) -> Self {
|
|
|
|
unreachable!()
|
2020-06-30 12:57:48 +00:00
|
|
|
}
|
|
|
|
}
|