marine/fluence-faas/src/errors.rs

57 lines
1.5 KiB
Rust
Raw Normal View History

2020-06-05 23:12:02 +03: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-06-06 21:34:13 +03:00
use std::io::Error as IOError;
2020-06-05 23:12:02 +03:00
use std::error::Error;
#[derive(Debug)]
pub enum FaaSError {
2020-06-06 21:34:13 +03:00
/// An error related to config parsing.
ConfigParseError(String),
2020-06-11 19:11:34 +03:00
/// Various errors related to file i/o.
2020-06-06 21:34:13 +03:00
IOError(String),
2020-06-05 23:12:02 +03:00
2020-06-16 14:20:33 +03:00
/// FCE errors.
EngineError(FCEError),
2020-06-05 23:12:02 +03:00
}
impl Error for FaaSError {}
2020-06-05 23:12:02 +03:00
impl std::fmt::Display for FaaSError {
2020-06-05 23:12:02 +03:00
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
FaaSError::ConfigParseError(err_msg) => write!(f, "{}", err_msg),
FaaSError::IOError(err_msg) => write!(f, "{}", err_msg),
FaaSError::EngineError(err) => write!(f, "{}", err),
2020-06-05 23:12:02 +03:00
}
}
}
impl From<IOError> for FaaSError {
2020-06-05 23:12:02 +03:00
fn from(err: IOError) -> Self {
FaaSError::IOError(format!("{}", err))
2020-06-05 23:12:02 +03:00
}
}
impl From<FCEError> for FaaSError {
2020-06-05 23:12:02 +03:00
fn from(err: FCEError) -> Self {
FaaSError::EngineError(err)
2020-06-05 23:12:02 +03:00
}
}