Skip to main content

tfparser_core/graph/
error.rs

1//! Errors emitted by the graph phase.
2
3use std::{path::PathBuf, sync::Arc};
4
5use thiserror::Error;
6
7use crate::ir::{Address, Span};
8
9/// Errors the graph builder can surface.
10///
11/// Per [15-resource-graph.md § 7], `UnresolvableModuleSource` and
12/// `DepthExceeded` are **not fatal** — the builder records them as
13/// [`crate::Diagnostic`]s and continues. Only [`GraphError::AddressCollision`]
14/// is fatal: it indicates a bug in the expansion logic, not user input.
15///
16/// [15-resource-graph.md § 7]: ../../../specs/15-resource-graph.md
17#[derive(Debug, Error)]
18#[non_exhaustive]
19pub enum GraphError {
20    /// A module call's `source` could not be resolved to a known local module.
21    /// Treated as a diagnostic at the call site, never fatal.
22    #[error("module source `{module_source}` referenced from {site:?} is not resolvable")]
23    UnresolvableModuleSource {
24        /// Verbatim source string from the call site.
25        module_source: Arc<str>,
26        /// Span of the call site.
27        site: Box<Span>,
28    },
29
30    /// Module recursion exceeded the configured depth cap. Records the path
31    /// where the cap fired.
32    #[error("module recursion exceeded depth {limit} at {site:?}")]
33    DepthExceeded {
34        /// Configured cap.
35        limit: u32,
36        /// Span of the offending call site.
37        site: Box<Span>,
38    },
39
40    /// Two flattened resources resolved to the same [`Address`]. Fatal: the
41    /// IR cannot represent two rows with the same address.
42    #[error("address collision: {0}")]
43    AddressCollision(Address),
44
45    /// Path-safety check failed when resolving a local module source.
46    /// Non-fatal in spec; the builder logs a diagnostic and skips the call.
47    #[error("path safety: {path:?}: {reason}")]
48    PathSafety {
49        /// Candidate path that failed.
50        path: PathBuf,
51        /// Why it failed.
52        reason: Arc<str>,
53    },
54}