use std::error;
use std::fmt;
use std::io;
#[derive(Debug)]
pub enum Error {
CheckProjectError(&'static str, String),
CreateError(&'static str, String),
CreateProjectError(&'static str, String),
CreateServiceError(&'static str, String),
CreateRecipeError(&'static str, String),
GetActionError(&'static str, String),
GetParameterError(&'static str, String),
InitProjectError(&'static str),
LoadContextError(&'static str),
LoadProjectError(&'static str),
LoadStoreError(&'static str),
RenderTemplateError(&'static str, String),
RunStageError(&'static str, String),
SetParameterError(&'static str, String),
GitError(git2::Error),
HandlebarsError(handlebars::TemplateRenderError),
IOError(std::io::Error),
JsonError(serde_json::Error),
PathError(std::path::StripPrefixError),
TomlDeError(toml::de::Error),
TomlSerError(toml::ser::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::CheckProjectError(msg, item) => {
write!(f, "Project file validation failed: {} ({})", msg, item)
}
Self::CreateError(msg, item) => {
write!(f, "Unable to create resource {}: {}", item, msg)
}
Self::CreateProjectError(msg, item) => {
write!(f, "Unable to create project {}: {}", item, msg)
}
Self::CreateServiceError(msg, item) => {
write!(f, "Unable to create service {}: {}", item, msg)
}
Self::CreateRecipeError(msg, item) => {
write!(f, "Unable to create recipe {}: {}", item, msg)
}
Self::GetParameterError(msg, item) => {
write!(f, "Failed to retrieve parameter: {} ({})", msg, item)
}
Self::GetActionError(msg, item) => {
write!(f, "Failed to retrieve action {}: {}", item, msg)
}
Self::InitProjectError(msg) => write!(f, "Failed to initialize the project: {}", msg),
Self::LoadContextError(msg) => write!(f, "Failed to load context: {}", msg),
Self::LoadProjectError(msg) => write!(f, "Could not load project: {}", msg),
Self::LoadStoreError(msg) => write!(f, "Could not load parameter store: {}", msg),
Self::RenderTemplateError(msg, item) => {
write!(f, "Failed to render template {}: {}", item, msg)
}
Self::RunStageError(msg, item) => write!(f, "Could not run stage {}: {}", item, msg),
Self::SetParameterError(msg, item) => {
write!(f, "Failed to store parameter {}: {}", item, msg)
}
Self::GitError(err) => err.fmt(f),
Self::HandlebarsError(err) => err.fmt(f),
Self::IOError(err) => err.fmt(f),
Self::JsonError(err) => err.fmt(f),
Self::PathError(err) => err.fmt(f),
Self::TomlDeError(err) => err.fmt(f),
Self::TomlSerError(err) => err.fmt(f),
}
}
}
impl error::Error for Error {}
impl From<git2::Error> for Error {
fn from(err: git2::Error) -> Self {
Self::GitError(err)
}
}
impl From<handlebars::TemplateRenderError> for Error {
fn from(err: handlebars::TemplateRenderError) -> Self {
Self::HandlebarsError(err)
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::IOError(err)
}
}
impl From<std::path::StripPrefixError> for Error {
fn from(err: std::path::StripPrefixError) -> Self {
Self::PathError(err)
}
}
impl From<serde_json::Error> for Error {
fn from(err: serde_json::Error) -> Self {
Self::JsonError(err)
}
}
impl From<toml::de::Error> for Error {
fn from(err: toml::de::Error) -> Self {
Self::TomlDeError(err)
}
}
impl From<toml::ser::Error> for Error {
fn from(err: toml::ser::Error) -> Self {
Self::TomlSerError(err)
}
}