use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum CompileError {
#[error("duplicate node id: {0:?}")]
DuplicateNodeId(String),
#[error("unknown {kind} in node {node:?}: {id:?} not registered")]
UnknownRef {
kind: &'static str,
node: String,
id: String,
},
#[error("entry node not found: {0:?}")]
MissingEntry(String),
#[error("edge endpoint not found: {0:?}")]
MissingEndpoint(String),
#[error("multiple edges from node: {0:?}")]
DuplicateEdgeSource(String),
#[error("node {node:?} missing required field: {field}")]
MissingField {
node: String,
field: &'static str,
},
#[error("edge from {0:?} has no target node")]
EdgeMissingBranchTarget(String),
#[error("edge from {0:?} has both `to` and `when`")]
EdgeHasBothToAndWhen(String),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn messages_include_offending_id() {
let e = CompileError::DuplicateNodeId("a".into());
assert!(e.to_string().contains("a"));
let e = CompileError::MissingEntry("start".into());
assert!(e.to_string().contains("start"));
}
}