use std::path::PathBuf;
use thiserror::Error;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum ManifestError {
#[error("Invalid Manifest Version '{0}'; if this is a valid version, ensure you have enabled the v{0} feature for the configuration")]
VersionError(String),
#[cfg(feature = "config")]
#[error(transparent)]
AssetReference(#[from] wick_asset_reference::Error),
#[cfg(feature = "config")]
#[error(transparent)]
AssetContainer(#[from] asset_container::Error),
#[error(transparent)]
LiquidConfig(#[from] liquid_json::Error),
#[error("Attempted to retrieve the types in a manifest before they've been fetched")]
TypesNotFetched,
#[error("Attempted to import a type that was not found in the manifest: {0}")]
TypeNotFound(String),
#[error("Manifest {} needs a format version (v0) or kind (v1+)", .0.as_ref().map_or("<raw>".to_owned(), |v|v.display().to_string()))]
NoFormat(Option<PathBuf>),
#[error("File not found {0}")]
FileNotFound(String),
#[error("Could not load file {0}")]
LoadError(String),
#[cfg(feature = "config")]
#[cfg_attr(
feature = "config",
error("Expected a {0} configuration but got a {1} configuration")
)]
UnexpectedConfigurationKind(crate::config::ConfigurationKind, crate::config::ConfigurationKind),
#[cfg(feature = "config")]
#[cfg_attr(feature = "config", error("Expected a {0} component but got a {1} component"))]
UnexpectedComponentType(crate::config::ComponentKind, crate::config::ComponentKind),
#[error("Could not parse manifest {} as YAML: {1} at line {}, column {}", .0.as_ref().map_or("<raw>".to_owned(), |v|v.display().to_string()), .2.as_ref().map_or("unknown".to_owned(),|l|l.line().to_string()), .2.as_ref().map_or("unknown".to_owned(),|l|l.column().to_string()))]
YamlError(Option<PathBuf>, String, Option<serde_yaml::Location>),
#[error("Invalid IP Address: {0}")]
BadIpAddress(String),
#[error("Invalid regular expression: {0}")]
InvalidRegex(String),
#[error("Invalid format: {0}")]
Invalid(serde_json::Error),
#[error("Invalid operation expression '{0}'. Must be in the form component_name::operation_name.")]
InvalidOperationExpression(String),
#[error(transparent)]
Parser(#[from] flow_expression_parser::Error),
#[error(transparent)]
TypeParser(#[from] wick_interface_types::ParserError),
#[error("could not convert a {0} into a {1}")]
VariantError(String, String),
#[error("Error parsing YAML as a string")]
Utf8,
#[error("Invalid authority: {0}")]
InvalidUrl(String),
#[error("id '{id}' undefined, IDs in scope are: {}", .ids.join(", "))]
IdNotFound {
id: String,
ids: Vec<String>,
},
#[error("Could not render configuration template: {0}")]
ConfigurationTemplate(String),
#[cfg(feature = "config")]
#[error(transparent)]
ConfigurationInvalid(#[from] wick_packet::Error),
#[error("Invalid template: could not turn an object or an array into a string")]
TemplateStructure,
#[error("Invalid template context, context must be an object")]
ContextBase,
#[error("Attempted to use configuration '{0}' before it was rendered")]
UnrenderedConfiguration(String),
#[cfg(feature = "config")]
#[cfg_attr(feature = "config", error(transparent))]
Reference(#[from] ReferenceError),
#[cfg(feature = "config")]
#[error(transparent)]
Builder(#[from] BuilderError),
#[error("Error converting configured Packet flags, use the singular version instead")]
InvalidPacketFlags,
}
#[cfg(feature = "config")]
#[derive(Error, Debug, Clone, Copy)]
pub enum ReferenceError {
#[error("Referenced item is not a component")]
Component,
#[error("Referenced item is not an imported types configuration")]
Types,
#[error("Referenced item is not a resource")]
Resource,
#[error("Expected a resource of type {expected}, found type {actual}")]
ResourceType {
expected: crate::config::resources::ResourceKind,
actual: crate::config::resources::ResourceKind,
},
}
#[cfg(feature = "config")]
#[derive(Error, Debug)]
pub enum BuilderError {
#[error("Uninitialized field: {0}")]
UninitializedField(&'static str),
#[error("Invalid builder configuration: {0}")]
ValidationError(String),
}
#[cfg(feature = "config")]
impl From<String> for BuilderError {
fn from(s: String) -> Self {
Self::ValidationError(s)
}
}
#[cfg(feature = "config")]
impl From<derive_builder::UninitializedFieldError> for BuilderError {
fn from(value: derive_builder::UninitializedFieldError) -> Self {
Self::UninitializedField(value.field_name())
}
}