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    #[error("JSON error: {0}")]
37    Json(#[from] serde_json::Error),
38    #[error("Anyhow error: {0}")]
39    Anyhow(#[from] anyhow::Error),
40}
41
42/// Error type specific to the `kotoba-workflow` crate.
43#[derive(Debug, Error)]
44pub enum WorkflowError {
45    #[error("Workflow not found: {0}")]
46    WorkflowNotFound(String),
47    // #[error("Activity execution failed: {0}")]
48    // ActivityFailed(#[from] ActivityError), // ActivityError is not defined here
49    #[error("Invalid strategy: {0}")]
50    InvalidStrategy(String),
51    #[error("Invalid workflow definition: {0}")]
52    InvalidDefinition(String),
53    #[error("Timeout exceeded")]
54    Timeout,
55    #[error("Compensation failed: {0}")]
56    CompensationFailed(String),
57    #[error("Graph operation failed: {0}")]
58    GraphError(String),
59    #[error("Storage error: {0}")]
60    StorageError(String),
61    #[error("Serialization error: {0}")]
62    SerializationError(#[from] serde_json::Error),
63    // #[error("Invalid step type for this executor: {0:?}")]
64    // InvalidStepType(kotoba_routing::schema::WorkflowStepType),
65    #[error("Context variable not found: {0}")]
66    ContextVariableNotFound(String),
67}
68
69/// Allow `WorkflowError` to be converted into `KotobaError`.
70/// This is the key to breaking the circular dependency.
71impl From<WorkflowError> for KotobaError {
72    fn from(err: WorkflowError) -> Self {
73        KotobaError::Workflow(err.to_string())
74    }
75}