tfparser_core/terragrunt/error.rs
1//! Errors emitted by the Terragrunt resolver.
2
3use std::{path::PathBuf, sync::Arc};
4
5use thiserror::Error;
6
7use crate::ir::Span;
8
9/// Errors the Terragrunt resolver can surface.
10///
11/// Per [14-terragrunt.md § 6], the variants mirror the spec text. Cycle /
12/// path-escape / depth-cap are recorded as [`crate::Diagnostic`]s on the
13/// returned [`crate::ir::TerragruntConfig`] in practice — only truly fatal
14/// I/O errors (the parent dir disappears mid-walk) bubble up as
15/// `Err(crate::Error)` via the `From` glue.
16///
17/// [14-terragrunt.md § 6]: ../../../specs/14-terragrunt.md
18#[derive(Debug, Error)]
19#[non_exhaustive]
20pub enum TerragruntError {
21 /// Include cycle detected. The vector captures the canonical stack at
22 /// the moment the cycle was detected; the offending file is the *next*
23 /// path the resolver would have entered.
24 #[error("terragrunt include cycle: {0:?}")]
25 Cycle(Vec<Arc<std::path::Path>>),
26
27 /// Include stack exceeded the configured depth cap.
28 #[error("terragrunt include depth limit ({limit}) exceeded")]
29 DepthExceeded {
30 /// Configured cap.
31 limit: u32,
32 },
33
34 /// A path resolved by a Terragrunt function escapes the workspace root.
35 #[error("terragrunt path escape: {path:?}")]
36 PathEscape {
37 /// Path that failed the descendant-of-root check.
38 path: PathBuf,
39 },
40
41 /// A Terragrunt function call failed.
42 #[error("terragrunt function `{func}`: {message}")]
43 Func {
44 /// Function name.
45 func: &'static str,
46 /// Message safe to log.
47 message: Box<str>,
48 /// Source span.
49 span: Box<Span>,
50 },
51}