Skip to main content

faucet_cli/
error.rs

1//! CLI-level error type. Wraps every failure mode the binary surfaces so
2//! `main()` can render a single, user-readable line per failure.
3
4use std::path::PathBuf;
5use thiserror::Error;
6
7/// Convenience alias used by every CLI module.
8pub type CliResult<T> = Result<T, CliError>;
9
10/// Top-level error variants for the `faucet` binary.
11#[derive(Debug, Error)]
12pub enum CliError {
13    /// Failed to read a config file from disk.
14    #[error("failed to read config file '{path}': {source}")]
15    ReadConfig {
16        path: PathBuf,
17        #[source]
18        source: std::io::Error,
19    },
20
21    /// The config file extension is neither `.yaml`/`.yml` nor `.json`.
22    #[error(
23        "unsupported config extension for '{path}' — use .yaml, .yml, or .json (mixed JSON/YAML in a single file is not allowed)"
24    )]
25    UnknownExtension { path: PathBuf },
26
27    /// Failed to parse the raw config text after interpolation.
28    #[error("failed to parse config '{path}': {message}")]
29    ParseConfig { path: PathBuf, message: String },
30
31    /// An `${env:VAR}` reference could not be resolved.
32    #[error("missing environment variable '{var}' referenced in config at '{location}'")]
33    MissingEnvVar { var: String, location: String },
34
35    /// A `${file:PATH}` reference could not be read.
36    #[error("failed to read interpolated file '{}' referenced in config: {source}", path.display())]
37    ReadInterpolatedFile {
38        path: PathBuf,
39        #[source]
40        source: std::io::Error,
41    },
42
43    #[error(
44        "interpolated file '{}' exceeds the {max_bytes}-byte limit for `${{file:...}}` — \
45         this directive is for small token/secret files, not bulk data",
46        path.display()
47    )]
48    InterpolatedFileTooLarge { path: PathBuf, max_bytes: u64 },
49
50    /// A `${row_id.path}` token referenced an unknown matrix row id at
51    /// expand-time (or a typo'd load-time prefix that survived to record-time).
52    #[error(
53        "interpolation '{token}' references unknown id '{id}' (must be a matrix row id, or one of env/file/secret)"
54    )]
55    UnknownInterpolationId { id: String, token: String },
56
57    /// A `${row_id.path}` resolved at record-time, but the dotted path doesn't
58    /// match any field in the parent record.
59    #[error("matrix row '{id}' has no field at path '{path}' in this parent record")]
60    MissingRecordField { id: String, path: String },
61
62    /// The named connector is unknown (or its feature flag is disabled in this build).
63    #[error("unknown {kind} '{name}'. Available: {available}")]
64    UnknownConnector {
65        kind: &'static str,
66        name: String,
67        available: String,
68    },
69
70    /// The state-store type referenced in the config is unknown or not compiled in.
71    #[error("unknown state store '{name}'. Available: {available}")]
72    UnknownStateStore { name: String, available: String },
73
74    /// A transform type referenced in the config is not recognised.
75    #[error("unknown transform '{name}'. Available: {available}")]
76    UnknownTransform { name: String, available: String },
77
78    /// The transform config block could not be deserialized into the expected shape.
79    #[error("invalid transform '{name}': {message}")]
80    InvalidTransform { name: String, message: String },
81
82    /// A connector config object failed to deserialize.
83    #[error("invalid config for {kind} '{name}': {message}")]
84    InvalidConnectorConfig {
85        kind: &'static str,
86        name: String,
87        message: String,
88    },
89
90    /// A scaffold target already exists.
91    #[error("refusing to overwrite existing file '{path}' — pass --force to overwrite")]
92    ScaffoldExists { path: PathBuf },
93
94    /// The CLI was invoked with `--from-env` but the required selector env var
95    /// (`FAUCET_SOURCE` or `FAUCET_SINK`) is unset.
96    #[error(
97        "missing required environment variable '{var}' — set it before invoking `faucet run --from-env`"
98    )]
99    MissingEnvSelector { var: String },
100
101    /// An explicit `--env-file` path does not exist on disk.
102    #[error("--env-file path '{}' does not exist", path.display())]
103    EnvFileNotFound { path: PathBuf },
104
105    /// `faucet run` invoked with neither a config path nor `--from-env`, and
106    /// auto-discovery found no `faucet.{yaml,yml,json}` in cwd.
107    #[error(
108        "no pipeline config: pass a path, --from-env, or create faucet.yaml (or .yml/.json) in the current directory"
109    )]
110    NoConfigOrFromEnv,
111
112    /// Both a scalar env var and its `_JSON` counterpart were set for the same field.
113    #[error(
114        "conflicting environment variables for field '{field}': both '{scalar_var}' and '{json_var}' are set — pick one"
115    )]
116    EnvConflict {
117        field: String,
118        scalar_var: String,
119        json_var: String,
120    },
121
122    /// A `*_JSON` env var did not parse as JSON.
123    #[error("environment variable '{var}' is not valid JSON: {message}")]
124    InvalidEnvJson { var: String, message: String },
125
126    /// `FAUCET_TRANSFORM_<N>` indices are not contiguous starting at 1.
127    #[error(
128        "transform env vars must be contiguous starting at FAUCET_TRANSFORM_1; index {missing} is missing"
129    )]
130    TransformIndexGap { missing: u32 },
131
132    /// A matrix row id collides with a load-time interpolation prefix.
133    #[error("matrix row id '{id}' is reserved (env, file, secret, matrix, pipeline)")]
134    ReservedRowId { id: String },
135
136    /// Two matrix rows declared the same id.
137    #[error("duplicate matrix row id '{id}'")]
138    DuplicateRowId { id: String },
139
140    /// A row's `parent:` field names a row that doesn't exist.
141    #[error("matrix row '{id}' references unknown parent '{parent}'")]
142    UnknownParent { id: String, parent: String },
143
144    /// The parent chain contains a cycle.
145    #[error("matrix has a parent cycle through: {}", ids.join(" -> "))]
146    ParentCycle { ids: Vec<String> },
147
148    /// A row's `depends_on:` list names a row that doesn't exist.
149    #[error("matrix row '{id}' depends on unknown row '{depends_on}'")]
150    UnknownDependency { id: String, depends_on: String },
151
152    /// The combined `parent:` + `depends_on:` graph contains a cycle.
153    #[error("matrix has a dependency cycle involving: {}", ids.join(", "))]
154    DependencyCycle { ids: Vec<String> },
155
156    /// Two parent records of the same matrix row resolved to the same
157    /// `parent_key` value, producing a colliding state-key suffix.
158    #[error(
159        "duplicate state key '{state_key}' for matrix row '{id}': two parent records resolve to the same `parent_key` value — choose a `parent_key` that is unique per record"
160    )]
161    DuplicateStateKey { id: String, state_key: String },
162
163    /// The state key derived from the pipeline name + row id (+ resolved
164    /// parent-key value) is not a valid state-store key. Caught up front at
165    /// unit construction rather than mid-run.
166    #[error("invalid state key '{state_key}' for row '{id}': {reason}")]
167    InvalidStateKey {
168        id: String,
169        state_key: String,
170        reason: String,
171    },
172
173    /// One or more matrix invocations failed under `on_error: continue`.
174    #[error("{count} pipeline invocation(s) failed (see logs above for details)")]
175    PipelineHadFailures { count: usize },
176
177    /// DLQ sink kind is not registered (not compiled in or feature disabled).
178    #[error("DLQ sink kind `{kind}` is not registered (in {context})")]
179    UnknownDlqSinkKind { kind: String, context: String },
180
181    /// DLQ budget field is set to zero (which is invalid; omit to mean 'unlimited').
182    #[error("DLQ {field} must be > 0 (got 0); omit the field to mean 'unlimited'")]
183    InvalidDlqBudget { field: &'static str },
184
185    /// A matrix row referenced a named template that doesn't exist in
186    /// `pipeline.sources` / `pipeline.sinks` (or the legacy `default`).
187    #[error(
188        "matrix row '{row_id}' references unknown {kind} template '{name}'. Known {kind} templates: {known}",
189        known = if known.is_empty() { String::from("(none defined)") } else { known.join(", ") }
190    )]
191    UnknownTemplate {
192        kind: &'static str,
193        name: String,
194        row_id: String,
195        known: Vec<String>,
196    },
197
198    /// A matrix row supplied no `ref:` and the legacy `default` template
199    /// doesn't exist either.
200    #[error(
201        "matrix row '{row_id}' has no {kind}: either set `{kind}: {{ ref: <name> }}` pointing at a `pipeline.{kind}s` template, or declare a legacy `pipeline.{kind}` block"
202    )]
203    MissingTemplate { kind: &'static str, row_id: String },
204
205    /// Both the legacy `pipeline.source` and `pipeline.sources.default` were
206    /// declared (same for sinks). The `default` slot can only be defined once.
207    #[error(
208        "{kind} template '{name}' is defined twice — declare it either via the singular `pipeline.{kind}` block or in `pipeline.{kind}s`, not both"
209    )]
210    DuplicateTemplate { kind: &'static str, name: String },
211
212    /// A sink template carries a `transforms:` field, which only sources support.
213    #[error(
214        "sink template '{name}' has `transforms:` — sinks cannot carry transforms; \
215         declare transforms on the source template, pipeline, or matrix row instead"
216    )]
217    TransformsOnSink { name: String },
218
219    /// A sink template carries `inherit_transforms:`, which only sources support.
220    #[error(
221        "sink template '{name}' has `inherit_transforms:` — sinks cannot carry the \
222         transform-inheritance flag; remove it"
223    )]
224    InheritTransformsOnSink { name: String },
225
226    /// A cycle was detected resolving `${vars.X}` / `${sources.X.PATH}` /
227    /// `${sinks.X.PATH}` references at load time.
228    #[error("interpolation cycle: {}", chain.join(" -> "))]
229    InterpolationCycle { chain: Vec<String> },
230
231    /// A config-composition include/extends chain contains a cycle.
232    #[error("config composition cycle: {}", chain.join(" -> "))]
233    CompositionCycle { chain: Vec<String> },
234
235    /// An `extends`/`!include` target file does not exist.
236    #[error(
237        "config composition: file '{}' referenced by '{}' not found",
238        path.display(),
239        referenced_by.display()
240    )]
241    IncludeNotFound {
242        path: PathBuf,
243        referenced_by: PathBuf,
244    },
245
246    /// Composition nesting exceeded the safety cap (extends/!include loop guard).
247    #[error(
248        "config composition nested deeper than {max} levels — check for an extends/!include loop"
249    )]
250    CompositionDepthExceeded { max: usize },
251
252    /// An `!include` tag had a non-string payload, an unsupported tag, or its
253    /// target failed structural checks.
254    #[error("invalid `!include` in '{}': {reason}", path.display())]
255    BadInclude { path: PathBuf, reason: String },
256
257    /// `--profile NAME` (or FAUCET_PROFILE) named a profile not declared under `profiles:`.
258    #[error(
259        "unknown profile '{name}'. Declared profiles: {}",
260        if known.is_empty() { String::from("(none — no `profiles:` block)") } else { known.join(", ") }
261    )]
262    UnknownProfile { name: String, known: Vec<String> },
263
264    /// A `${vars.X}` token referenced an undefined var.
265    #[error(
266        "interpolation '{token}' references unknown var '{name}' (define it under top-level `vars:`)"
267    )]
268    UnknownVarsRef { name: String, token: String },
269
270    /// A `${sources.X.PATH}` or `${sinks.X.PATH}` token referenced an
271    /// undefined template, or a dotted path that doesn't resolve inside it.
272    #[error("interpolation '{token}' could not be resolved: {reason}")]
273    UnknownTemplateRef { token: String, reason: String },
274
275    /// A connector's `auth: { ref }` named a provider not declared in the
276    /// top-level `auth:` catalog.
277    #[error(
278        "auth references unknown provider '{name}'. Declared providers: {}",
279        if known.is_empty() { String::from("(none)") } else { known.join(", ") }
280    )]
281    UnknownAuthProvider { name: String, known: Vec<String> },
282
283    /// A top-level `auth:` provider spec failed to build.
284    #[error("failed to build auth provider '{name}': {message}")]
285    AuthProviderBuild { name: String, message: String },
286
287    /// A `--select`/`--only`/`--skip` token matched no matrix row id (#370).
288    /// Guards against typos silently producing a partial or empty run.
289    #[error(
290        "{flag} '{token}' matched no matrix row. Available rows: {}",
291        if available.is_empty() { String::from("(none)") } else { available.join(", ") }
292    )]
293    NoMatchForSelector {
294        flag: &'static str,
295        token: String,
296        available: Vec<String>,
297    },
298
299    /// A `--status <tier>` value is not one of the readiness-ladder tiers (#371).
300    #[error("unknown status '{value}'. Valid tiers: {}", available.join(", "))]
301    UnknownStatus {
302        value: String,
303        available: Vec<String>,
304    },
305
306    /// A `--tag <t>` value matches no row's tags (#376). Typo protection.
307    #[error(
308        "unknown tag '{tag}'. Tags present in this config: {}",
309        if available.is_empty() { String::from("(none — no row declares tags)") } else { available.join(", ") }
310    )]
311    UnknownTag { tag: String, available: Vec<String> },
312
313    /// A `--include-parents <policy>` value is not `off`/`eligible`/`all` (#377).
314    #[error("unknown include_parents policy '{value}' (expected off, eligible, or all)")]
315    UnknownIncludeParents { value: String },
316
317    /// Matrix-only selectors were passed for a config with no `matrix:`
318    /// (single anonymous invocation) — nothing to select among (#370/#376).
319    #[error(
320        "selector(s) {flags} require a `matrix:` — this config has a single anonymous invocation (nothing to select)"
321    )]
322    SelectorsWithoutMatrix { flags: String },
323
324    /// The resolved run set is empty after status gating / tag narrowing / skip
325    /// (#371). Not a silent no-op — names each row's status and how to include.
326    #[error(
327        "no matrix rows selected to run. Rows and their status: {}. \
328         Widen the run set with --status <tier>, --select <id>, or --tag <t>",
329        rows.join(", ")
330    )]
331    EmptyRunSet { rows: Vec<String> },
332
333    /// A run-set row structurally depends on an ancestor that is not in the run
334    /// set, under the active `include_parents` policy (#377). Lists every
335    /// offending `dependent → ancestor (edge)` pair.
336    #[error(
337        "run-set dependency violation (include_parents={policy}): {}. \
338         Select the ancestor by id (--select <id>), or loosen the policy \
339         (--include-parents eligible|all)",
340        pairs.join("; ")
341    )]
342    RunSetMissingAncestors {
343        pairs: Vec<String>,
344        policy: &'static str,
345    },
346
347    /// A config-level validation failure that isn't covered by a more specific
348    /// variant (e.g. an invalid `quality:` block, or a quality check that
349    /// requires a DLQ when none is configured).
350    #[error("config error: {0}")]
351    Config(String),
352
353    /// Pass-through for failures bubbling up from `faucet-core` or a connector.
354    #[error(transparent)]
355    Faucet(#[from] faucet_core::FaucetError),
356
357    /// Pass-through I/O error.
358    #[error("io error: {0}")]
359    Io(#[from] std::io::Error),
360
361    /// Observability stack (Prometheus / tracing) failed to install.
362    #[error("observability install failed: {0}")]
363    Observability(String),
364
365    /// An internal invariant was violated (a bug). Surfaced instead of
366    /// silently producing a partial result.
367    #[error("internal error: {0}")]
368    Internal(String),
369
370    /// A secret-manager directive used a scheme whose backend feature was not
371    /// compiled into this binary.
372    #[error(
373        "secret directive uses scheme '{scheme}' but this binary was built without \
374         the `secrets-{scheme}` feature — rebuild with `--features secrets-{scheme}` (or `secrets`)"
375    )]
376    SecretBackendDisabled { scheme: String },
377
378    /// The secrets manager has no secret at the given reference.
379    #[error("secret '{reference}' not found in {scheme}")]
380    SecretNotFound { scheme: String, reference: String },
381
382    /// The secret fetch failed (network / API error).
383    #[error("failed to fetch secret '{reference}' from {scheme}: {source}")]
384    SecretFetchFailed {
385        scheme: String,
386        reference: String,
387        #[source]
388        source: Box<dyn std::error::Error + Send + Sync>,
389    },
390
391    /// No ambient credentials were available for the backend.
392    #[error("could not authenticate to {scheme}: {hint}")]
393    SecretAuthFailed { scheme: String, hint: String },
394
395    /// A `#field` selector was used on a secret that is not JSON.
396    #[error("secret '{reference}' from {scheme} is not JSON, but a '#field' selector was used")]
397    SecretNotJson { scheme: String, reference: String },
398
399    /// A `#field` selector named a key absent from the secret JSON.
400    #[error(
401        "secret '{reference}' from {scheme} has no field '{field}' (available: {})",
402        if available.is_empty() { String::from("(none — secret is an empty object)") } else { available.join(", ") }
403    )]
404    SecretFieldMissing {
405        scheme: String,
406        reference: String,
407        field: String,
408        available: Vec<String>,
409    },
410
411    /// A secret directive was found while loading via the synchronous path.
412    #[error(
413        "config references a secrets manager (${{vault:…}} / ${{aws-sm:…}} / …) which requires \
414         the async load path — load via `faucet run`/`validate`/`preview` rather than the sync API"
415    )]
416    SecretsRequireAsyncLoad,
417
418    /// One or more `faucet doctor` preflight probes failed. The checklist is
419    /// printed by the command; `main` maps this to an exit code equal to the
420    /// failed-probe count (clamped to 255).
421    #[error("{failed} preflight probe(s) failed")]
422    DoctorFailed { failed: usize },
423
424    /// One or more `faucet test` cases failed. The report is printed by the
425    /// command; `main` maps this to an exit code equal to the failed-case
426    /// count (clamped to 255).
427    #[error("{failed} test case(s) failed")]
428    TestsFailed { failed: usize },
429
430    /// One or more `faucet backfill` units failed. The per-unit report is
431    /// printed by the command (progress is already durably recorded, so
432    /// `--resume` retries only the failures); `main` maps this to an exit
433    /// code equal to the failed-unit count (clamped to 255).
434    #[error("{failed} backfill unit(s) failed")]
435    BackfillFailed { failed: usize },
436
437    /// A `faucet serve` startup or runtime failure (bind, auth gate, etc.).
438    #[error("serve error: {0}")]
439    Serve(String),
440
441    /// `overlap_policy: forbid` saw a tick fire while a run was still in flight.
442    #[error("scheduled run overlap with overlap_policy: forbid — previous run still in progress")]
443    ScheduleOverlapForbidden,
444}
445
446impl From<faucet_core::InstallError> for CliError {
447    fn from(e: faucet_core::InstallError) -> Self {
448        CliError::Observability(e.to_string())
449    }
450}
451
452#[cfg(test)]
453mod secrets_error_tests {
454    use super::*;
455
456    #[test]
457    fn secret_errors_render_reference_not_value() {
458        let e = CliError::SecretNotFound {
459            scheme: "vault".into(),
460            reference: "secret/data/app#token".into(),
461        };
462        let msg = e.to_string();
463        assert!(msg.contains("vault"));
464        assert!(msg.contains("secret/data/app#token"));
465
466        let e = CliError::SecretFieldMissing {
467            scheme: "aws-sm".into(),
468            reference: "prod/db".into(),
469            field: "password".into(),
470            available: vec!["username".into(), "host".into()],
471        };
472        let msg = e.to_string();
473        assert!(msg.contains("password"));
474        assert!(msg.contains("username") && msg.contains("host"));
475
476        let e = CliError::SecretBackendDisabled {
477            scheme: "azure-kv".into(),
478        };
479        assert!(e.to_string().contains("secrets-azure-kv"));
480
481        assert!(
482            CliError::SecretsRequireAsyncLoad
483                .to_string()
484                .contains("async")
485        );
486    }
487
488    #[test]
489    fn fetch_auth_notjson_errors_render_safely() {
490        let e = CliError::SecretFetchFailed {
491            scheme: "vault".into(),
492            reference: "secret/data/app#token".into(),
493            source: "connection refused".into(),
494        };
495        let msg = e.to_string();
496        assert!(msg.contains("vault") && msg.contains("secret/data/app#token"));
497
498        let e = CliError::SecretAuthFailed {
499            scheme: "aws-sm".into(),
500            hint: "set AWS_PROFILE".into(),
501        };
502        assert!(e.to_string().contains("aws-sm") && e.to_string().contains("set AWS_PROFILE"));
503
504        let e = CliError::SecretNotJson {
505            scheme: "vault".into(),
506            reference: "secret/raw".into(),
507        };
508        assert!(e.to_string().contains("not JSON"));
509    }
510
511    #[test]
512    fn field_missing_with_empty_available_has_no_dangling_list() {
513        let e = CliError::SecretFieldMissing {
514            scheme: "vault".into(),
515            reference: "secret/data/app".into(),
516            field: "token".into(),
517            available: vec![],
518        };
519        let msg = e.to_string();
520        assert!(!msg.ends_with("(available: )"));
521        assert!(msg.contains("token"));
522    }
523}
524
525#[cfg(test)]
526mod tests {
527    use super::*;
528
529    #[test]
530    fn missing_env_selector_renders() {
531        let e = CliError::MissingEnvSelector {
532            var: "FAUCET_SOURCE".to_owned(),
533        };
534        let msg = e.to_string();
535        assert!(msg.contains("FAUCET_SOURCE"));
536        assert!(msg.contains("--from-env"));
537    }
538
539    #[test]
540    fn env_conflict_names_both_vars() {
541        let e = CliError::EnvConflict {
542            field: "auth".to_owned(),
543            scalar_var: "FAUCET_SOURCE_REST_AUTH".to_owned(),
544            json_var: "FAUCET_SOURCE_REST_AUTH_JSON".to_owned(),
545        };
546        let msg = e.to_string();
547        assert!(msg.contains("FAUCET_SOURCE_REST_AUTH"));
548        assert!(msg.contains("FAUCET_SOURCE_REST_AUTH_JSON"));
549    }
550
551    #[test]
552    fn invalid_env_json_names_var_and_parse_error() {
553        let e = CliError::InvalidEnvJson {
554            var: "FAUCET_SOURCE_REST_AUTH_JSON".to_owned(),
555            message: "expected value at line 1 column 1".to_owned(),
556        };
557        let msg = e.to_string();
558        assert!(msg.contains("FAUCET_SOURCE_REST_AUTH_JSON"));
559        assert!(msg.contains("expected value"));
560    }
561
562    #[test]
563    fn transform_index_gap_reports_missing_index() {
564        let e = CliError::TransformIndexGap { missing: 2 };
565        let msg = e.to_string();
566        assert!(msg.contains('2'));
567        assert!(msg.to_ascii_lowercase().contains("transform"));
568    }
569
570    #[test]
571    fn unknown_template_lists_known_names() {
572        let e = CliError::UnknownTemplate {
573            kind: "source",
574            name: "users_api".into(),
575            row_id: "load_users".into(),
576            known: vec!["customers_api".into(), "orders_api".into()],
577        };
578        let msg = e.to_string();
579        assert!(msg.contains("users_api"));
580        assert!(msg.contains("load_users"));
581        assert!(msg.contains("customers_api"));
582    }
583
584    #[test]
585    fn duplicate_template_names_kind() {
586        let e = CliError::DuplicateTemplate {
587            kind: "sink",
588            name: "default".into(),
589        };
590        let msg = e.to_string();
591        assert!(msg.contains("sink"));
592        assert!(msg.contains("default"));
593    }
594
595    #[test]
596    fn interpolation_cycle_renders_chain() {
597        let e = CliError::InterpolationCycle {
598            chain: vec!["vars.a".into(), "vars.b".into(), "vars.a".into()],
599        };
600        let msg = e.to_string();
601        assert!(msg.contains("vars.a"));
602        assert!(msg.contains("vars.b"));
603    }
604
605    #[test]
606    fn composition_cycle_renders_chain() {
607        let e = CliError::CompositionCycle {
608            chain: vec!["a.yaml".into(), "b.yaml".into(), "a.yaml".into()],
609        };
610        let msg = e.to_string();
611        assert!(msg.contains("a.yaml") && msg.contains("b.yaml"));
612        assert!(msg.contains(" -> "));
613    }
614
615    #[test]
616    fn unknown_profile_lists_known() {
617        let e = CliError::UnknownProfile {
618            name: "staging".into(),
619            known: vec!["dev".into(), "prod".into()],
620        };
621        let msg = e.to_string();
622        assert!(msg.contains("staging") && msg.contains("dev") && msg.contains("prod"));
623
624        let none = CliError::UnknownProfile {
625            name: "x".into(),
626            known: vec![],
627        };
628        assert!(none.to_string().contains("no `profiles:` block"));
629    }
630
631    #[test]
632    fn include_not_found_names_both_paths() {
633        let e = CliError::IncludeNotFound {
634            path: std::path::PathBuf::from("base.yaml"),
635            referenced_by: std::path::PathBuf::from("app.yaml"),
636        };
637        let msg = e.to_string();
638        assert!(msg.contains("base.yaml") && msg.contains("app.yaml"));
639    }
640
641    #[test]
642    fn composition_depth_exceeds_renders_max() {
643        assert!(
644            CliError::CompositionDepthExceeded { max: 32 }
645                .to_string()
646                .contains("32")
647        );
648    }
649
650    #[test]
651    fn bad_include_names_path_and_reason() {
652        let e = CliError::BadInclude {
653            path: std::path::PathBuf::from("f.yaml"),
654            reason: "!include payload must be a string path".into(),
655        };
656        assert!(e.to_string().contains("f.yaml") && e.to_string().contains("string path"));
657    }
658}