Skip to main content

feynkit_cff/
error.rs

1use crate::{EdgeId, VertexId};
2use thiserror::Error;
3
4/// Errors reported while validating a topology or generating a CFF expression.
5#[derive(Clone, Debug, Error, PartialEq, Eq)]
6pub enum CffError {
7    #[error("a CFF graph must contain at least one vertex")]
8    EmptyGraph,
9    #[error("CFF generation supports at most {maximum} vertices, received {actual}")]
10    TooManyVertices { actual: usize, maximum: usize },
11    #[error("edge {edge} refers to vertex {vertex}, but the graph has {vertex_count} vertices")]
12    UnknownVertex {
13        edge: EdgeId,
14        vertex: VertexId,
15        vertex_count: usize,
16    },
17    #[error("edge id {0} occurs more than once")]
18    DuplicateEdge(EdgeId),
19    #[error("the internal topology is disconnected")]
20    DisconnectedGraph,
21    #[error(
22        "original vertex {vertex} cannot be represented in a CFF surface; the maximum vertex id is {maximum}"
23    )]
24    VertexIdentityOutOfRange { vertex: VertexId, maximum: usize },
25    #[error("edge {edge} refers to vertex {vertex} outside the selected subgraph")]
26    SubgraphEndpointOutsideSelection { edge: EdgeId, vertex: VertexId },
27    #[error("edge {0} is not an internal edge")]
28    NotInternalEdge(EdgeId),
29    #[error("edge {0} does not exist")]
30    UnknownEdge(EdgeId),
31    #[error("diagram edge {0} connects two external vertices")]
32    ExternalToExternalEdge(EdgeId),
33    #[error("diagram edge {0} has an endpoint excluded as external without external metadata")]
34    MissingExternalMetadata(EdgeId),
35    #[error("contracted edge {0} cannot also have a fixed orientation")]
36    OrientedContractedEdge(EdgeId),
37    #[error("fixed orientation for edge {0} must be default or reversed")]
38    UndirectedFixedEdge(EdgeId),
39    #[error(
40        "generating {candidate_count} orientations exceeds the configured maximum of {maximum}"
41    )]
42    TooManyOrientations {
43        candidate_count: usize,
44        maximum: usize,
45    },
46    #[error("the number of free internal edges cannot be represented on this platform")]
47    OrientationCountOverflow,
48    #[error("acyclic orientation {orientation} has no source or sink with a connected complement")]
49    NoSourceOrSink { orientation: usize },
50    /// See [`three_dimensional_reps::cff_recursion::SurfaceChainError`] for the
51    /// inputs known to reach this error.
52    #[error(
53        "acyclic orientation {orientation} reached a CFF vertex without a completing contraction; the topology is unsupported or violates a CFF generation invariant"
54    )]
55    NoContractionBranch { orientation: usize },
56    #[error("CFF branches ended at different depths for orientation {orientation}")]
57    UnevenBranchDepth { orientation: usize },
58    #[error("the external-shift coefficient for edge {edge} exceeds the i64 range")]
59    ExternalShiftOverflow { edge: EdgeId },
60    #[error("internal CFF invariant failed: {0}")]
61    Invariant(String),
62}