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
//! Errors of the schema generator. Messages follow helm-schema's, so a failure reads the same
//! as in the Go tool; [`GenerateError::Annotation`] also exposes the line it names.
use super::yaml::YamlError;
/// Why a schema could not be generated.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum GenerateError {
/// The `values.yaml` (or a `Chart.yaml`-level YAML document) is not valid YAML.
#[error("{0}")]
Yaml(#[from] YamlError),
/// An annotation block or comment could not be read: an unclosed `# @schema` block, or YAML
/// that does not decode into a schema. `line` is the line inside the annotation block that
/// helm-schema's message names (relative to the block, not to the file).
#[error("{context}: {message}")]
Annotation {
/// What was being read, such as `error parsing comment of key image`.
context: String,
/// The line named by `message`, when it names one.
line: Option<usize>,
/// The decoder's message.
message: String,
},
/// A decoded annotation is inconsistent, a `$ref` cannot be resolved, a type cannot be
/// inferred or a final schema is invalid.
#[error("{context}: {message}")]
Schema {
/// What was being processed, such as `error validating schema of key port`.
context: String,
/// The problem.
message: String,
},
/// A dependency of the chart cannot be bound or merged.
#[error("{0}")]
Dependency(String),
}
impl GenerateError {
pub(super) fn annotation(context: String, message: String) -> Self {
let line = message.find("line ").and_then(|i| {
let digits: String = message[i + 5..]
.chars()
.take_while(char::is_ascii_digit)
.collect();
digits.parse().ok()
});
Self::Annotation {
context,
line,
message,
}
}
pub(super) fn schema(context: String, message: String) -> Self {
Self::Schema { context, message }
}
}
/// The result of schema generation.
pub type Result<T> = std::result::Result<T, GenerateError>;