kasa_core/
error.rs

1//! Error types for kasa-core.
2//!
3//! This module defines the error types returned by the library.
4
5use thiserror::Error;
6
7/// Error type for kasa-core operations.
8#[derive(Debug, Error)]
9pub enum Error {
10    /// Connection to the device failed.
11    #[error("connection failed: {0}")]
12    ConnectionFailed(String),
13
14    /// Operation timed out.
15    #[error("timeout: {0}")]
16    Timeout(String),
17
18    /// Authentication failed (KLAP protocol).
19    #[error("authentication failed: {0}")]
20    AuthenticationFailed(String),
21
22    /// Protocol error (unexpected response format, etc.).
23    #[error("protocol error: {0}")]
24    Protocol(String),
25
26    /// I/O error during communication.
27    #[error("I/O error: {0}")]
28    IoError(String),
29
30    /// Device returned an error response.
31    #[error("device error: {0}")]
32    DeviceError(String),
33
34    /// Failed to parse device response.
35    #[error("parse error: {0}")]
36    ParseError(String),
37}
38
39impl From<std::io::Error> for Error {
40    fn from(err: std::io::Error) -> Self {
41        Error::IoError(err.to_string())
42    }
43}