Skip to main content

feagi_agent/core/
error.rs

1// Copyright 2025 Neuraville Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Error types for FEAGI Agent SDK
5
6/// Result type alias using SdkError
7pub type Result<T> = std::result::Result<T, SdkError>;
8
9/// Error types for the FEAGI Agent SDK
10#[derive(Debug, thiserror::Error)]
11pub enum SdkError {
12    /// ZMQ communication error
13    #[error("ZMQ error: {0}")]
14    Zmq(#[from] zeromq::ZmqError),
15
16    /// JSON serialization/deserialization error
17    #[error("JSON error: {0}")]
18    Json(#[from] serde_json::Error),
19
20    /// Registration failed
21    #[error("Registration failed: {0}")]
22    RegistrationFailed(String),
23
24    /// Agent not registered
25    #[error("Agent not registered - call connect() first")]
26    NotRegistered,
27
28    /// Connection timeout
29    #[error("Connection timeout: {0}")]
30    Timeout(String),
31
32    /// Invalid configuration
33    #[error("Invalid configuration: {0}")]
34    InvalidConfig(String),
35
36    /// Agent already connected
37    #[error("Agent already connected")]
38    AlreadyConnected,
39
40    /// Heartbeat failure
41    #[error("Heartbeat failed: {0}")]
42    HeartbeatFailed(String),
43
44    /// Thread communication error
45    #[error("Thread communication error: {0}")]
46    ThreadError(String),
47
48    /// Generic SDK error
49    #[error("SDK error: {0}")]
50    Other(String),
51}
52
53impl SdkError {
54    /// Check if error is retryable (for reconnection logic)
55    pub fn is_retryable(&self) -> bool {
56        matches!(
57            self,
58            SdkError::Zmq(_) | SdkError::Timeout(_) | SdkError::HeartbeatFailed(_)
59        )
60    }
61}