Skip to main content

camel_core/lifecycle/domain/
error.rs

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