Skip to main content

synth_core/
error.rs

1//! Error types for Synth
2
3/// Result type for Synth operations
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Errors that can occur during synthesis
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9    /// Component parsing failed
10    #[error("Failed to parse component: {0}")]
11    ParseError(String),
12
13    /// Component validation failed
14    #[error("Component validation failed: {0}")]
15    ValidationError(String),
16
17    /// Synthesis failed
18    #[error("Synthesis failed: {0}")]
19    SynthesisError(String),
20
21    /// Target not supported
22    #[error("Target not supported: {0}")]
23    UnsupportedTarget(String),
24
25    /// Instruction not supported on target
26    #[error("Unsupported instruction for target: {0}")]
27    UnsupportedInstruction(String),
28
29    /// Memory layout error
30    #[error("Memory layout error: {0}")]
31    MemoryLayoutError(String),
32
33    /// MPU/PMP configuration error
34    #[error("Hardware protection error: {0}")]
35    HardwareProtectionError(String),
36
37    /// IO error
38    #[error("IO error: {0}")]
39    IoError(#[from] std::io::Error),
40
41    /// Other errors
42    #[error("{0}")]
43    Other(String),
44}
45
46impl Error {
47    /// Create a parse error
48    pub fn parse<S: Into<String>>(msg: S) -> Self {
49        Error::ParseError(msg.into())
50    }
51
52    /// Create a validation error
53    pub fn validation<S: Into<String>>(msg: S) -> Self {
54        Error::ValidationError(msg.into())
55    }
56
57    /// Create a synthesis error
58    pub fn synthesis<S: Into<String>>(msg: S) -> Self {
59        Error::SynthesisError(msg.into())
60    }
61}