Skip to main content

camel_core/lifecycle/domain/
error.rs

1use std::fmt;
2
3use thiserror::Error;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum DomainError {
7    InvalidTransition { from: String, to: String },
8    NotFound(String),
9    AlreadyExists(String),
10    InvalidState(String),
11}
12
13impl fmt::Display for DomainError {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        match self {
16            DomainError::InvalidTransition { from, to } => {
17                write!(f, "invalid transition: {from} -> {to}")
18            }
19            DomainError::NotFound(id) => write!(f, "not found: {id}"),
20            DomainError::AlreadyExists(id) => write!(f, "already exists: {id}"),
21            DomainError::InvalidState(msg) => write!(f, "invalid state: {msg}"),
22        }
23    }
24}
25
26impl std::error::Error for DomainError {}
27
28/// Error type for language registration operations on [`CamelContext`].
29///
30/// This is distinct from [`camel_language_api::error::LanguageError`], which
31/// covers language-evaluation concerns (parse, eval, unknown variable, etc.).
32/// Registration is a context-configuration invariant, not a language concern.
33#[derive(Debug, Clone, PartialEq, Eq, Error)]
34pub enum LanguageRegistryError {
35    #[error("language '{name}' is already registered")]
36    AlreadyRegistered { name: String },
37}