Skip to main content

cortexai_cloudflare/
error.rs

1//! Error types for Cloudflare Workers agent
2
3use thiserror::Error;
4
5/// Errors that can occur when using the Cloudflare agent
6#[derive(Error, Debug)]
7pub enum CloudflareError {
8    /// HTTP request failed
9    #[error("HTTP request failed: {0}")]
10    HttpError(String),
11
12    /// Failed to parse response
13    #[error("Failed to parse response: {0}")]
14    ParseError(String),
15
16    /// Provider API returned an error
17    #[error("Provider error: {0}")]
18    ProviderError(String),
19
20    /// Configuration error
21    #[error("Configuration error: {0}")]
22    ConfigError(String),
23
24    /// KV store error
25    #[error("KV store error: {0}")]
26    KvError(String),
27
28    /// Serialization error
29    #[error("Serialization error: {0}")]
30    SerializationError(String),
31
32    /// Stream error
33    #[error("Stream error: {0}")]
34    StreamError(String),
35
36    /// Worker error
37    #[error("Worker error: {0}")]
38    WorkerError(String),
39}
40
41impl From<worker::Error> for CloudflareError {
42    fn from(err: worker::Error) -> Self {
43        CloudflareError::WorkerError(err.to_string())
44    }
45}
46
47impl From<serde_json::Error> for CloudflareError {
48    fn from(err: serde_json::Error) -> Self {
49        CloudflareError::SerializationError(err.to_string())
50    }
51}
52
53impl From<cortexai_llm_client::LlmClientError> for CloudflareError {
54    fn from(err: cortexai_llm_client::LlmClientError) -> Self {
55        CloudflareError::ProviderError(err.to_string())
56    }
57}
58
59/// Result type for Cloudflare agent operations
60pub type Result<T> = std::result::Result<T, CloudflareError>;