1use std::fmt;
7
8#[derive(Debug, Clone)]
10pub enum Error {
11 ParseError(String),
13
14 TypeError { expected: String, found: String },
16
17 DeterminismViolation(String),
19
20 ContractViolation {
22 commitment: String,
23 violation: String,
24 },
25
26 ValidationError(String),
28
29 ExecutionError(String),
31
32 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
59pub type Result<T> = std::result::Result<T, Error>;