hdc_rs/
error.rs

1//! Error types for HDC client operations
2
3use std::io;
4use thiserror::Error;
5
6/// Result type alias for HDC operations
7pub type Result<T> = std::result::Result<T, HdcError>;
8
9/// Errors that can occur during HDC operations
10#[derive(Error, Debug)]
11pub enum HdcError {
12    /// I/O error occurred during communication
13    #[error("I/O error: {0}")]
14    Io(#[from] io::Error),
15
16    /// Invalid protocol data received
17    #[error("Protocol error: {0}")]
18    Protocol(String),
19
20    /// Handshake failed
21    #[error("Handshake failed: {0}")]
22    HandshakeFailed(String),
23
24    /// Connection not established
25    #[error("Not connected to HDC server")]
26    NotConnected,
27
28    /// Invalid banner received
29    #[error("Invalid banner: expected 'OHOS HDC', got {0:?}")]
30    InvalidBanner(Vec<u8>),
31
32    /// Buffer size error
33    #[error("Buffer error: {0}")]
34    BufferError(String),
35
36    /// Command execution failed
37    #[error("Command failed: {0}")]
38    CommandFailed(String),
39
40    /// Timeout occurred
41    #[error("Operation timed out")]
42    Timeout,
43
44    /// Device not found
45    #[error("Device not found: {0}")]
46    DeviceNotFound(String),
47
48    /// UTF-8 conversion error
49    #[error("UTF-8 error: {0}")]
50    Utf8(#[from] std::string::FromUtf8Error),
51}