Skip to main content

cp_ast_core/operation/
error.rs

1use crate::constraint::{ConstraintId, ExpectedType};
2use crate::structure::NodeId;
3
4/// Detail about a constraint violation.
5#[derive(Debug, Clone, PartialEq)]
6pub struct ViolationDetail {
7    /// ID of the violated constraint.
8    pub constraint_id: ConstraintId,
9    /// Human-readable description of the violation.
10    pub description: String,
11    /// Optional suggestion for fixing the violation.
12    pub suggestion: Option<String>,
13}
14
15/// Errors that can occur when applying operations.
16#[derive(Debug, Clone, PartialEq)]
17pub enum OperationError {
18    /// Type mismatch between expected and actual.
19    TypeMismatch {
20        expected: ExpectedType,
21        actual: String,
22        context: String,
23    },
24    /// Target node not found in the AST.
25    NodeNotFound { node: NodeId },
26    /// Slot is already occupied.
27    SlotOccupied {
28        node: NodeId,
29        current_occupant: String,
30    },
31    /// One or more constraints were violated.
32    ConstraintViolation {
33        violated_constraints: Vec<ViolationDetail>,
34    },
35    /// The operation is invalid for the given context.
36    InvalidOperation { action: String, reason: String },
37}