wick_config/
error.rs

1use std::path::PathBuf;
2
3use thiserror::Error;
4
5/// Wick Manifest's Errors.
6#[derive(Error, Debug)]
7#[non_exhaustive]
8pub enum ManifestError {
9  /// Invalid version found in the parsed manifest.
10  #[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  /// Error related to asset references.
14  #[cfg(feature = "config")]
15  #[error(transparent)]
16  AssetReference(#[from] wick_asset_reference::Error),
17
18  /// Error related to fetching asset references.
19  #[cfg(feature = "config")]
20  #[error(transparent)]
21  AssetContainer(#[from] asset_container::Error),
22
23  /// Error rendering liquid JSON configuration.
24  #[error(transparent)]
25  LiquidConfig(#[from] liquid_json::Error),
26
27  /// Attempted to retrieve the types in a manifest before they've been fetched.
28  #[error("Attempted to retrieve the types in a manifest before they've been fetched")]
29  TypesNotFetched,
30
31  /// Attempted to import a type that was not found in the manifest.
32  #[error("Attempted to import a type that was not found in the manifest: {0}")]
33  TypeNotFound(String),
34
35  /// No format version or kind found in the parsed manifest.
36  #[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  /// Manifest not found at the specified path.
40  #[error("File not found {0}")]
41  FileNotFound(String),
42
43  /// Could not load file.
44  #[error("Could not load file {0}")]
45  LoadError(String),
46
47  /// Thrown when a specific type of configuration was expected but a different type was found.
48  #[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  /// Thrown when a specific type of component was expected but a different type was found.
56  #[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 deserializing YAML manifest.
61  #[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  /// IP address in manifest is invalid.
65  #[error("Invalid IP Address: {0}")]
66  BadIpAddress(String),
67
68  /// Invalid regular expression.
69  #[error("Invalid regular expression: {0}")]
70  InvalidRegex(String),
71
72  /// Invalid format of passed data. Check the error message for details.
73  #[error("Invalid format: {0}")]
74  Invalid(serde_json::Error),
75
76  /// Invalid operation expression. Must be in the form component_name::operation_name.
77  #[error("Invalid operation expression '{0}'. Must be in the form component_name::operation_name.")]
78  InvalidOperationExpression(String),
79
80  /// Parser error.
81  #[error(transparent)]
82  Parser(#[from] flow_expression_parser::Error),
83
84  /// Type Parser error.
85  #[error(transparent)]
86  TypeParser(#[from] wick_interface_types::ParserError),
87
88  /// Error converting an enum to a specific variant.
89  #[error("could not convert a {0} into a {1}")]
90  VariantError(String, String),
91
92  /// Error parsing YAML as a string.
93  #[error("Error parsing YAML as a string")]
94  Utf8,
95
96  /// Invalid authority format
97  #[error("Invalid authority: {0}")]
98  InvalidUrl(String),
99
100  /// Identifier not found.
101  #[error("id '{id}' undefined, IDs in scope are: {}", .ids.join(", "))]
102  IdNotFound {
103    /// The lookup id.
104    id: String,
105    /// The ids that exist in the lookup scope
106    ids: Vec<String>,
107  },
108
109  /// Attempted to use configuration before it was renderable.
110  #[error("Could not render configuration template: {0}")]
111  ConfigurationTemplate(String),
112
113  /// Passed [wick_packet::RuntimeConfig] is invalid for the configuration required by this component.
114  #[cfg(feature = "config")]
115  #[error(transparent)]
116  ConfigurationInvalid(#[from] wick_packet::Error),
117
118  /// Attempted to serialize a complex [liquid_json::LiquidJson] template into a string.
119  #[error("Invalid template: could not turn an object or an array into a string")]
120  TemplateStructure,
121
122  /// Attempted to create a template render context from a non-object value.
123  #[error("Invalid template context, context must be an object")]
124  ContextBase,
125
126  /// Attempted to use configuration before it was rendered.
127  #[error("Attempted to use configuration '{0}' before it was rendered")]
128  UnrenderedConfiguration(String),
129
130  /// Error resolving reference.
131  #[cfg(feature = "config")]
132  #[cfg_attr(feature = "config", error(transparent))]
133  Reference(#[from] ReferenceError),
134
135  /// Error building a configuration
136  #[cfg(feature = "config")]
137  #[error(transparent)]
138  Builder(#[from] BuilderError),
139
140  /// Error converting configured Packet flags.
141  #[error("Error converting configured Packet flags, use the singular version instead")]
142  InvalidPacketFlags,
143
144  /// Error when trying to use a component as a bound reference when it wasn't bound.
145  #[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)]
151/// Errors that can occur when trying to dereference a configuration name or id.
152pub enum ReferenceError {
153  /// The referenced item was not a component.
154  #[error("Referenced item is not a component")]
155  Component,
156
157  /// The referenced item was not an imported types configuration.
158  #[error("Referenced item is not an imported types configuration")]
159  Types,
160
161  /// The referenced item was not a resource.
162  #[error("Referenced item is not a resource")]
163  Resource,
164
165  /// The resource was not the requested type.
166  #[error("Expected a resource of type {expected}, found type {actual}")]
167  ResourceType {
168    /// The expected resource type.
169    expected: crate::config::resources::ResourceKind,
170    /// The actual resource type.
171    actual: crate::config::resources::ResourceKind,
172  },
173}
174
175#[cfg(feature = "config")]
176/// Errors generated when building a configuration.
177#[derive(Error, Debug)]
178pub enum BuilderError {
179  /// Uninitialized field
180  #[error("Uninitialized field: {0}")]
181  UninitializedField(&'static str),
182  /// Invalid builder configuration
183  #[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}