1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
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) } }