1use thiserror::Error;
5
6#[derive(Debug, Error)]
8#[non_exhaustive]
9pub enum CompileError {
10 #[error("duplicate node id: {0:?}")]
12 DuplicateNodeId(String),
13 #[error("unknown {kind} in node {node:?}: {id:?} not registered")]
15 UnknownRef {
16 kind: &'static str,
18 node: String,
20 id: String,
22 },
23 #[error("entry node not found: {0:?}")]
25 MissingEntry(String),
26 #[error("edge endpoint not found: {0:?}")]
28 MissingEndpoint(String),
29 #[error("multiple edges from node: {0:?}")]
31 DuplicateEdgeSource(String),
32 #[error("node {node:?} missing required field: {field}")]
34 MissingField {
35 node: String,
37 field: &'static str,
39 },
40 #[error("edge from {0:?} has no target node")]
43 EdgeMissingBranchTarget(String),
44 #[error("edge from {0:?} has both `to` and `when`")]
47 EdgeHasBothToAndWhen(String),
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn messages_include_offending_id() {
56 let e = CompileError::DuplicateNodeId("a".into());
57 assert!(e.to_string().contains("a"));
58 let e = CompileError::MissingEntry("start".into());
59 assert!(e.to_string().contains("start"));
60 }
61}