Skip to main content

ap_client/
error.rs

1//! Error types for the remote client
2
3use ap_error::ap_error;
4use thiserror::Error;
5
6/// Errors that can occur in the remote client
7#[ap_error(flat)]
8#[derive(Debug, Error)]
9pub enum ClientError {
10    /// Failed to connect to the proxy server
11    #[error("Failed to connect to proxy: {0}")]
12    ConnectionFailed(String),
13
14    /// WebSocket error occurred
15    #[error("WebSocket error: {0}")]
16    WebSocket(String),
17
18    /// Authentication with proxy failed
19    #[error("Proxy authentication failed: {0}")]
20    ProxyAuthFailed(String),
21
22    /// Invalid pairing code format
23    #[error("Invalid pairing code: {0}")]
24    InvalidPairingCode(String),
25
26    /// Noise protocol error
27    #[error("Noise protocol error: {0}")]
28    NoiseProtocol(String),
29
30    /// Handshake failed
31    #[error("Handshake failed: {0}")]
32    HandshakeFailed(String),
33
34    /// Timeout waiting for response
35    #[error("Timeout: {0}")]
36    Timeout(String),
37
38    /// Secure channel not established
39    #[error("Secure channel not established")]
40    SecureChannelNotEstablished,
41
42    /// Client not initialized
43    #[error("Client not initialized - call connect() first")]
44    NotInitialized,
45
46    /// Credential request failed
47    #[error("Credential request failed: {0}")]
48    CredentialRequestFailed(String),
49
50    /// Serialization/deserialization error
51    #[error("Serialization error: {0}")]
52    Serialization(String),
53
54    /// Session cache error
55    #[error("Session cache error: {0}")]
56    SessionCache(String),
57
58    /// Keypair storage error
59    #[error("Keypair storage error: {0}")]
60    KeypairStorage(String),
61
62    /// Channel closed unexpectedly
63    #[error("Channel closed")]
64    ChannelClosed,
65
66    /// Identity storage error
67    #[error("Identity storage error: {0}")]
68    IdentityStorageFailed(String),
69
70    /// Rendezvous code resolution failed
71    #[error("Rendezvous resolution failed: {0}")]
72    RendezvousResolutionFailed(String),
73
74    /// Invalid rendezvous code format
75    #[error("Invalid rendezvous code: {0}")]
76    InvalidRendezvousCode(String),
77
78    /// User rejected fingerprint verification
79    #[error("Fingerprint verification rejected by user")]
80    FingerprintRejected,
81
82    /// Invalid state for operation
83    #[error("Invalid state: expected {expected}, got {current}")]
84    InvalidState { expected: String, current: String },
85
86    /// Session not found for fingerprint
87    #[error("Session not found for fingerprint")]
88    SessionNotFound,
89}
90
91impl From<ap_noise::error::NoiseProtocolError> for ClientError {
92    fn from(err: ap_noise::error::NoiseProtocolError) -> Self {
93        ClientError::NoiseProtocol(err.to_string())
94    }
95}
96
97impl From<serde_json::Error> for ClientError {
98    fn from(err: serde_json::Error) -> Self {
99        ClientError::Serialization(err.to_string())
100    }
101}
102
103impl From<ap_proxy_protocol::ProxyError> for ClientError {
104    fn from(err: ap_proxy_protocol::ProxyError) -> Self {
105        ClientError::ConnectionFailed(err.to_string())
106    }
107}