Skip to main content

frp_weave/
error.rs

1//! Error types for the weave layer.
2
3use frp_plexus::{AtomId, BlockId, EdgeId, PortId};
4use thiserror::Error;
5
6#[derive(Debug, Error)]
7pub enum WeaveError {
8    #[error("validation failed: {0}")]
9    ValidationFailed(String),
10
11    #[error("missing atom: {0:?}")]
12    MissingAtom(AtomId),
13
14    #[error("incompatible ports: '{from}' -> '{to}'")]
15    IncompatiblePorts { from: String, to: String },
16
17    #[error("archetype not found: {0}")]
18    ArchetypeNotFound(String),
19
20    #[error("block not found: {0:?}")]
21    BlockNotFound(BlockId),
22
23    #[error("edge not found: {0:?}")]
24    EdgeNotFound(EdgeId),
25
26    #[error("port not found: {0:?}")]
27    PortNotFound(PortId),
28
29    #[error("template error: {0}")]
30    TemplateError(String),
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn display_validation_failed() {
39        let e = WeaveError::ValidationFailed("bad schema".to_string());
40        assert_eq!(e.to_string(), "validation failed: bad schema");
41    }
42
43    #[test]
44    fn display_missing_atom() {
45        let e = WeaveError::MissingAtom(AtomId::new(42));
46        assert!(e.to_string().contains("42"));
47    }
48
49    #[test]
50    fn display_incompatible_ports() {
51        let e = WeaveError::IncompatiblePorts {
52            from: "output_a".to_string(),
53            to: "input_b".to_string(),
54        };
55        assert_eq!(e.to_string(), "incompatible ports: 'output_a' -> 'input_b'");
56    }
57
58    #[test]
59    fn display_archetype_not_found() {
60        let e = WeaveError::ArchetypeNotFound("my_arch".to_string());
61        assert_eq!(e.to_string(), "archetype not found: my_arch");
62    }
63}