helm_schema/error.rs
1use std::path::PathBuf;
2
3/// Errors produced while loading charts, analyzing templates, and emitting schemas.
4#[derive(Debug, thiserror::Error)]
5pub enum CliError {
6 /// Virtual-filesystem operation failed.
7 #[error("vfs error: {0}")]
8 Vfs(#[from] vfs::VfsError),
9
10 /// Operating-system I/O operation failed.
11 #[error("io error: {0}")]
12 Io(#[from] std::io::Error),
13
14 /// YAML input could not be decoded.
15 #[error("yaml error: {0}")]
16 Yaml(#[from] serde_yaml::Error),
17
18 /// JSON input or output could not be decoded or encoded.
19 #[error("json error: {0}")]
20 Json(#[from] serde_json::Error),
21
22 /// Helm template source could not be parsed.
23 #[error("template parse error: {0}")]
24 TemplateParse(#[from] helm_schema_ast::ParseError),
25
26 /// Chart discovery found no analyzable charts.
27 #[error("no charts discovered")]
28 NoChartsDiscovered,
29
30 /// A discovered subchart path has no usable chart name.
31 #[error("subchart name missing for {path}")]
32 SubchartNameMissing {
33 /// Path of the unnamed subchart.
34 path: String,
35 },
36
37 /// An archive does not contain a chart manifest.
38 #[error("no Chart.yaml found in archive {archive}")]
39 NoChartYamlInArchive {
40 /// Path or identifier of the archive.
41 archive: String,
42 },
43
44 /// The output directory could not be created.
45 #[error("failed to create output directory {path}")]
46 CreateOutputDir {
47 /// Directory creation target.
48 path: PathBuf,
49 /// Underlying filesystem failure.
50 #[source]
51 source: std::io::Error,
52 },
53
54 /// A generated schema could not be written.
55 #[error("failed to write output {path}")]
56 WriteOutput {
57 /// Output file that could not be written.
58 path: PathBuf,
59 /// Underlying filesystem failure.
60 #[source]
61 source: std::io::Error,
62 },
63
64 /// Wraps any failure surfaced by the `jsonschema` / `referencing`
65 /// full-inlining pass: file-not-found, JSON parse error, malformed
66 /// URI, pointer-to-nowhere, missing anchor, etc. The wrapped variant
67 /// carries the structured cause so callers can pattern-match on the
68 /// underlying problem (e.g. `Unretrievable { uri, source }` vs
69 /// `PointerToNowhere { pointer }`) rather than parsing a string.
70 #[error("$ref resolution failed: {0}")]
71 Referencing(#[from] jsonschema::ReferencingError),
72
73 /// A self-contained schema could not be produced from external references.
74 #[error("$ref bundling failed: {0}")]
75 RefBundling(String),
76
77 /// A local filesystem path cannot be represented as a file URI.
78 #[error("filesystem path cannot be represented as a file URI: {path}")]
79 InvalidFileUriPath {
80 /// Filesystem path that could not be encoded.
81 path: PathBuf,
82 },
83
84 /// A file URI cannot be represented as a local filesystem path.
85 #[error("file URI cannot be represented as a local filesystem path: {uri}")]
86 InvalidFileUri {
87 /// File URI that could not be decoded.
88 uri: String,
89 },
90
91 /// One loaded document exceeded the configured byte budget.
92 #[error("load budget exceeded for {subject} (limit {limit_bytes} bytes)")]
93 LoadBudgetExceeded {
94 /// Document or archive member being loaded.
95 subject: String,
96 /// Maximum permitted byte count.
97 limit_bytes: usize,
98 },
99
100 /// An archive or directory exceeded the configured entry budget.
101 #[error("load budget exceeded for {subject} (limit {limit_entries} entries)")]
102 LoadEntryBudgetExceeded {
103 /// Archive or directory being enumerated.
104 subject: String,
105 /// Maximum permitted entry count.
106 limit_entries: usize,
107 },
108
109 /// An archive member would escape its extraction root.
110 #[error("unsafe archive entry path {entry_path} in {archive}")]
111 UnsafeArchiveEntryPath {
112 /// Archive containing the unsafe member.
113 archive: String,
114 /// Untrusted member path rejected by validation.
115 entry_path: String,
116 },
117
118 /// Mutually-exclusive CLI flags or otherwise-invalid combination
119 /// detected after `clap` parsing succeeded.
120 #[error("invalid CLI options: {0}")]
121 CliValidation(String),
122}
123
124/// Result returned by the schema engine's public operations.
125pub type EngineResult<T> = std::result::Result<T, CliError>;