Skip to main content

pedant_graph/
error.rs

1//! Why a graph build refused.
2//!
3//! Every variant names the exact join or ceiling that failed. No refusal
4//! returns a partial graph, none panics, and none exposes the snapshot identity
5//! bytes it compared.
6
7use crate::limits::GraphCollection;
8
9/// A refusal taken while projecting one resolution into a graph.
10#[derive(Debug, thiserror::Error)]
11pub enum GraphBuildError {
12    /// The supplied snapshot and resolution were requested for other targets.
13    #[error("the snapshot and the resolution describe different root targets")]
14    RootTargetMismatch,
15    /// The supplied snapshot is not the one the resolution was validated
16    /// against, even though both name the same root target.
17    #[error("the snapshot is not the one this resolution was validated against")]
18    SnapshotFingerprintMismatch,
19    /// A report unit has no graph container, or no source scope beneath one.
20    #[error("unit {unit} has no binding in this resolution")]
21    MissingUnitBinding {
22        /// The report-local unit identifier that no binding answers for.
23        unit: u32,
24    },
25    /// A report unit is bound to a build unit the supplied snapshot does not
26    /// hold, which is a binding that names nothing rather than a missing one.
27    #[error("unit {unit} is bound to a build unit this snapshot does not hold")]
28    DanglingUnitBinding {
29        /// The report-local unit identifier whose binding names nothing.
30        unit: u32,
31    },
32    /// Two report units are bound to one build unit, so one unit-qualified
33    /// source would have two owners.
34    #[error("report units {held} and {unit} are bound to one build unit")]
35    SharedUnitBinding {
36        /// The report-local unit identifier that bound the build unit first.
37        held: u32,
38        /// The report-local unit identifier that bound it again.
39        unit: u32,
40    },
41    /// A snapshot dependency edge names a build unit with no graph container.
42    #[error(
43        "dependency edge {edge} ({alias}) names a build unit this graph holds no container for"
44    )]
45    MissingDependencyUnit {
46        /// The edge's position among the snapshot's dependency edges.
47        edge: u32,
48        /// The namespace-local name that edge declares its target under.
49        alias: Box<str>,
50    },
51    /// A stated site names a source the bound unit does not instantiate.
52    #[error("unit {unit} instantiates no source at {path}")]
53    MissingSourceNode {
54        /// The report-local unit identifier the site belongs to.
55        unit: u32,
56        /// The normalized repository-relative path the site named.
57        path: Box<str>,
58    },
59    /// One report unit instantiates one normalized path twice, so a second file
60    /// node would be minted for a source that already holds one.
61    #[error("unit {unit} instantiates the source at {path} more than once")]
62    RepeatedUnitSource {
63        /// The report-local unit identifier that instantiates it twice.
64        unit: u32,
65        /// The normalized repository-relative path stated more than once.
66        path: Box<str>,
67    },
68    /// The report states a different number of references and resolution
69    /// records, so no pairing between them is stated at all.
70    #[error("the report states {references} references and {records} resolution records")]
71    ReferenceRecordMismatch {
72        /// How many references the report states.
73        references: u32,
74        /// How many resolution records the report states.
75        records: u32,
76    },
77    /// A stated join names a definition this graph holds no node for.
78    #[error("definition {definition} has no node in this graph")]
79    MissingDefinitionNode {
80        /// The report-local definition identifier that named nothing.
81        definition: u32,
82    },
83    /// An edge was produced for a reference record this graph does not hold.
84    #[error("reference {reference} has no record in this graph")]
85    MissingReferenceRecord {
86        /// The reference identity that answers for no record.
87        reference: u32,
88    },
89    /// A containment edge names a node this graph holds no record for.
90    #[error("containment names node {node}, which this graph holds no record for")]
91    UnknownContainmentNode {
92        /// The node identity the containment relation named.
93        node: u32,
94    },
95    /// One node is contained by more than one parent.
96    #[error("node {child} is contained by more than one parent, including {parent}")]
97    MultiplyContained {
98        /// One parent the child is contained by.
99        parent: u32,
100        /// The multiply-contained child.
101        child: u32,
102    },
103    /// One node below the unit roots is contained by nothing.
104    #[error("node {node} is contained by no parent and is not a unit root")]
105    UnparentedNode {
106        /// The node no containment edge claims.
107        node: u32,
108    },
109    /// One unit root is contained by another node.
110    #[error("unit root {root} is contained by node {parent}")]
111    RootHasParent {
112        /// The unit root that must own itself.
113        root: u32,
114        /// The node that claims it.
115        parent: u32,
116    },
117    /// One containment chain returns to a node it already visited.
118    #[error("node {node} contains itself through its own ancestors")]
119    ContainmentCycle {
120        /// The node the chain returned to.
121        node: u32,
122    },
123    /// One collection reached its configured ceiling.
124    #[error("the {collection} collection cannot exceed {limit} entries")]
125    CapacityExceeded {
126        /// Which collection refused the insertion.
127        collection: GraphCollection,
128        /// The ceiling that collection is bounded by.
129        limit: u32,
130    },
131}