Skip to main content

icl_core/
error.rs

1//! Error types for ICL runtime
2//!
3//! All fallible operations return `Result<T, Error>`.
4//! Error types provide context for diagnosis.
5
6use std::fmt;
7
8/// ICL runtime error types
9#[derive(Debug, Clone)]
10pub enum Error {
11    /// Syntax or structure violation during parsing
12    ParseError(String),
13
14    /// Type mismatch in contract
15    TypeError { expected: String, found: String },
16
17    /// Non-deterministic behavior detected
18    DeterminismViolation(String),
19
20    /// Contract commitment or postcondition violated
21    ContractViolation {
22        commitment: String,
23        violation: String,
24    },
25
26    /// Invariant or constraint validation failure
27    ValidationError(String),
28
29    /// Runtime execution failure
30    ExecutionError(String),
31
32    /// Normalization failure
33    NormalizationError(String),
34}
35
36impl fmt::Display for Error {
37    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38        match self {
39            Error::ParseError(msg) => write!(f, "Parse error: {}", msg),
40            Error::TypeError { expected, found } => {
41                write!(f, "Type mismatch: expected {}, found {}", expected, found)
42            }
43            Error::DeterminismViolation(msg) => write!(f, "Determinism violation: {}", msg),
44            Error::ContractViolation {
45                commitment,
46                violation,
47            } => {
48                write!(f, "Contract violation - {}: {}", commitment, violation)
49            }
50            Error::ValidationError(msg) => write!(f, "Validation error: {}", msg),
51            Error::ExecutionError(msg) => write!(f, "Execution error: {}", msg),
52            Error::NormalizationError(msg) => write!(f, "Normalization error: {}", msg),
53        }
54    }
55}
56
57impl std::error::Error for Error {}
58
59/// Result type alias for ICL operations
60pub type Result<T> = std::result::Result<T, Error>;