vtcode_core/gemini/streaming/
errors.rs

1use std::time::Duration;
2
3/// Streaming error types for better error classification and handling
4#[derive(Debug, Clone)]
5pub enum StreamingError {
6    /// Network-related errors (connection, timeout, DNS, etc.)
7    NetworkError { message: String, is_retryable: bool },
8    /// API-related errors (rate limits, authentication, etc.)
9    ApiError {
10        status_code: u16,
11        message: String,
12        is_retryable: bool,
13    },
14    /// Response parsing errors
15    ParseError {
16        message: String,
17        raw_response: String,
18    },
19    /// Timeout errors
20    TimeoutError {
21        operation: String,
22        duration: Duration,
23    },
24    /// Content validation errors
25    ContentError { message: String },
26    /// Streaming-specific errors
27    StreamingError {
28        message: String,
29        partial_content: Option<String>,
30    },
31}
32
33impl std::fmt::Display for StreamingError {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        match self {
36            StreamingError::NetworkError { message, .. } => {
37                write!(f, "Network error: {}", message)
38            }
39            StreamingError::ApiError {
40                status_code,
41                message,
42                ..
43            } => {
44                write!(f, "API error ({}): {}", status_code, message)
45            }
46            StreamingError::ParseError { message, .. } => {
47                write!(f, "Parse error: {}", message)
48            }
49            StreamingError::TimeoutError {
50                operation,
51                duration,
52            } => {
53                write!(f, "Timeout during {} after {:?}", operation, duration)
54            }
55            StreamingError::ContentError { message } => {
56                write!(f, "Content error: {}", message)
57            }
58            StreamingError::StreamingError { message, .. } => {
59                write!(f, "Streaming error: {}", message)
60            }
61        }
62    }
63}
64
65impl std::error::Error for StreamingError {}