1use std::path::PathBuf;
2
3use thiserror::Error;
4
5#[derive(Error, Debug)]
7#[non_exhaustive]
8pub enum ManifestError {
9 #[error("Invalid Manifest Version '{0}'; if this is a valid version, ensure you have enabled the v{0} feature for the configuration")]
11 VersionError(String),
12
13 #[cfg(feature = "config")]
15 #[error(transparent)]
16 AssetReference(#[from] wick_asset_reference::Error),
17
18 #[cfg(feature = "config")]
20 #[error(transparent)]
21 AssetContainer(#[from] asset_container::Error),
22
23 #[error(transparent)]
25 LiquidConfig(#[from] liquid_json::Error),
26
27 #[error("Attempted to retrieve the types in a manifest before they've been fetched")]
29 TypesNotFetched,
30
31 #[error("Attempted to import a type that was not found in the manifest: {0}")]
33 TypeNotFound(String),
34
35 #[error("Manifest {} needs a format version (v0) or kind (v1+)", .0.as_ref().map_or("<raw>".to_owned(), |v|v.display().to_string()))]
37 NoFormat(Option<PathBuf>),
38
39 #[error("File not found {0}")]
41 FileNotFound(String),
42
43 #[error("Could not load file {0}")]
45 LoadError(String),
46
47 #[cfg(feature = "config")]
49 #[cfg_attr(
50 feature = "config",
51 error("Expected a {0} configuration but got a {1} configuration")
52 )]
53 UnexpectedConfigurationKind(crate::config::ConfigurationKind, crate::config::ConfigurationKind),
54
55 #[cfg(feature = "config")]
57 #[cfg_attr(feature = "config", error("Expected a {0} component but got a {1} component"))]
58 UnexpectedComponentType(crate::config::ComponentKind, crate::config::ComponentKind),
59
60 #[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()))]
62 YamlError(Option<PathBuf>, String, Option<serde_yaml::Location>),
63
64 #[error("Invalid IP Address: {0}")]
66 BadIpAddress(String),
67
68 #[error("Invalid regular expression: {0}")]
70 InvalidRegex(String),
71
72 #[error("Invalid format: {0}")]
74 Invalid(serde_json::Error),
75
76 #[error("Invalid operation expression '{0}'. Must be in the form component_name::operation_name.")]
78 InvalidOperationExpression(String),
79
80 #[error(transparent)]
82 Parser(#[from] flow_expression_parser::Error),
83
84 #[error(transparent)]
86 TypeParser(#[from] wick_interface_types::ParserError),
87
88 #[error("could not convert a {0} into a {1}")]
90 VariantError(String, String),
91
92 #[error("Error parsing YAML as a string")]
94 Utf8,
95
96 #[error("Invalid authority: {0}")]
98 InvalidUrl(String),
99
100 #[error("id '{id}' undefined, IDs in scope are: {}", .ids.join(", "))]
102 IdNotFound {
103 id: String,
105 ids: Vec<String>,
107 },
108
109 #[error("Could not render configuration template: {0}")]
111 ConfigurationTemplate(String),
112
113 #[cfg(feature = "config")]
115 #[error(transparent)]
116 ConfigurationInvalid(#[from] wick_packet::Error),
117
118 #[error("Invalid template: could not turn an object or an array into a string")]
120 TemplateStructure,
121
122 #[error("Invalid template context, context must be an object")]
124 ContextBase,
125
126 #[error("Attempted to use configuration '{0}' before it was rendered")]
128 UnrenderedConfiguration(String),
129
130 #[cfg(feature = "config")]
132 #[cfg_attr(feature = "config", error(transparent))]
133 Reference(#[from] ReferenceError),
134
135 #[cfg(feature = "config")]
137 #[error(transparent)]
138 Builder(#[from] BuilderError),
139
140 #[error("Error converting configured Packet flags, use the singular version instead")]
142 InvalidPacketFlags,
143
144 #[error("Tried to use a component as a bound reference when it wasn't bound")]
146 InvalidReference,
147}
148
149#[cfg(feature = "config")]
150#[derive(Error, Debug, Clone, Copy)]
151pub enum ReferenceError {
153 #[error("Referenced item is not a component")]
155 Component,
156
157 #[error("Referenced item is not an imported types configuration")]
159 Types,
160
161 #[error("Referenced item is not a resource")]
163 Resource,
164
165 #[error("Expected a resource of type {expected}, found type {actual}")]
167 ResourceType {
168 expected: crate::config::resources::ResourceKind,
170 actual: crate::config::resources::ResourceKind,
172 },
173}
174
175#[cfg(feature = "config")]
176#[derive(Error, Debug)]
178pub enum BuilderError {
179 #[error("Uninitialized field: {0}")]
181 UninitializedField(&'static str),
182 #[error("Invalid builder configuration: {0}")]
184 ValidationError(String),
185}
186
187#[cfg(feature = "config")]
188impl From<String> for BuilderError {
189 fn from(s: String) -> Self {
190 Self::ValidationError(s)
191 }
192}
193
194#[cfg(feature = "config")]
195impl From<derive_builder::UninitializedFieldError> for BuilderError {
196 fn from(value: derive_builder::UninitializedFieldError) -> Self {
197 Self::UninitializedField(value.field_name())
198 }
199}