kotoba_errors/
lib.rs

1//! `kotoba-errors`
2//!
3//! Shared error types for the Kotoba ecosystem to prevent circular dependencies.
4
5use thiserror::Error;
6
7/// The primary error type for the entire Kotoba ecosystem.
8#[derive(Debug, Error)]
9pub enum KotobaError {
10    #[error("Parse error: {0}")]
11    Parse(String),
12    #[error("Execution error: {0}")]
13    Execution(String),
14    #[error("Storage error: {0}")]
15    Storage(String),
16    #[error("Validation error: {0}")]
17    Validation(String),
18    #[error("Rewrite error: {0}")]
19    Rewrite(String),
20    #[error("Security error: {0}")]
21    Security(String),
22    #[error("IO error: {0}")]
23    Io(#[from] std::io::Error),
24    #[error("Invalid argument: {0}")]
25    InvalidArgument(String),
26    #[error("Not found: {0}")]
27    NotFound(String),
28    #[error("Configuration error: {0}")]
29    Configuration(String),
30    #[error("Serialization error: {0}")]
31    Serialization(String),
32    #[error("Network error: {0}")]
33    Network(String),
34    #[error("Workflow error: {0}")]
35    Workflow(String), // Variant to hold stringified WorkflowError
36}
37
38/// Error type specific to the `kotoba-workflow` crate.
39#[derive(Debug, Error)]
40pub enum WorkflowError {
41    #[error("Workflow not found: {0}")]
42    WorkflowNotFound(String),
43    // #[error("Activity execution failed: {0}")]
44    // ActivityFailed(#[from] ActivityError), // ActivityError is not defined here
45    #[error("Invalid strategy: {0}")]
46    InvalidStrategy(String),
47    #[error("Invalid workflow definition: {0}")]
48    InvalidDefinition(String),
49    #[error("Timeout exceeded")]
50    Timeout,
51    #[error("Compensation failed: {0}")]
52    CompensationFailed(String),
53    #[error("Graph operation failed: {0}")]
54    GraphError(String),
55    #[error("Storage error: {0}")]
56    StorageError(String),
57    #[error("Serialization error: {0}")]
58    SerializationError(#[from] serde_json::Error),
59    // #[error("Invalid step type for this executor: {0:?}")]
60    // InvalidStepType(kotoba_routing::schema::WorkflowStepType),
61    #[error("Context variable not found: {0}")]
62    ContextVariableNotFound(String),
63}
64
65/// Allow `WorkflowError` to be converted into `KotobaError`.
66/// This is the key to breaking the circular dependency.
67impl From<WorkflowError> for KotobaError {
68    fn from(err: WorkflowError) -> Self {
69        KotobaError::Workflow(err.to_string())
70    }
71}