iflow_cli_sdk_rust/
error.rs

1//! Error types for iFlow SDK
2//!
3//! This module defines all the error types that can occur when using the iFlow SDK.
4
5use thiserror::Error;
6
7/// Main error type for iFlow SDK
8///
9/// This enum encompasses all possible errors that can occur when using the iFlow SDK.
10#[derive(Error, Debug)]
11pub enum IFlowError {
12    /// Connection related errors
13    #[error("Connection error: {0}")]
14    Connection(String),
15
16    /// Protocol related errors
17    #[error("Protocol error: {0}")]
18    Protocol(String),
19
20    /// Authentication related errors
21    #[error("Authentication error: {0}")]
22    Authentication(String),
23
24    /// Timeout related errors
25    #[error("Timeout error: {0}")]
26    Timeout(String),
27
28    /// Tool call related errors
29    #[error("Tool call error: {0}")]
30    ToolCall(String),
31
32    /// Validation related errors
33    #[error("Validation error: {0}")]
34    Validation(String),
35
36    /// Transport related errors
37    #[error("Transport error: {0}")]
38    Transport(String),
39
40    /// JSON parsing errors
41    #[error("JSON parsing error: {0}")]
42    JsonParse(#[from] serde_json::Error),
43
44    /// WebSocket related errors (deprecated)
45    #[error("WebSocket error: {0}")]
46    WebSocket(String),
47
48    /// IO related errors
49    #[error("IO error: {0}")]
50    Io(#[from] std::io::Error),
51
52    /// Process manager related errors
53    #[error("Process manager error: {0}")]
54    ProcessManager(String),
55
56    /// Not connected error
57    #[error("Not connected")]
58    NotConnected,
59
60    /// Session not found error
61    #[error("Session not found")]
62    SessionNotFound,
63
64    /// Invalid message format error
65    #[error("Invalid message format: {0}")]
66    InvalidMessage(String),
67
68    /// Unknown error
69    #[error("Unknown error: {0}")]
70    Unknown(String),
71}
72
73/// Result type alias for iFlow SDK
74///
75/// This is a convenience alias for `std::result::Result<T, IFlowError>`.
76pub type Result<T> = std::result::Result<T, IFlowError>;