Skip to main content

adb_wire/
error.rs

1use std::io;
2
3/// Error type for ADB wire protocol operations.
4#[derive(Debug)]
5pub enum Error {
6    /// TCP connection or I/O failure.
7    Io(io::Error),
8    /// ADB server returned FAIL with a message.
9    Adb(String),
10    /// Unexpected response from ADB server.
11    Protocol(String),
12}
13
14impl std::fmt::Display for Error {
15    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16        match self {
17            Error::Io(e) => write!(f, "io: {e}"),
18            Error::Adb(msg) => write!(f, "adb: {msg}"),
19            Error::Protocol(msg) => write!(f, "protocol: {msg}"),
20        }
21    }
22}
23
24impl std::error::Error for Error {
25    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
26        match self {
27            Error::Io(e) => Some(e),
28            _ => None,
29        }
30    }
31}
32
33impl From<io::Error> for Error {
34    fn from(e: io::Error) -> Self {
35        Error::Io(e)
36    }
37}
38
39impl Error {
40    pub(crate) fn timed_out(msg: &str) -> Self {
41        Error::Io(io::Error::new(io::ErrorKind::TimedOut, msg))
42    }
43}
44
45pub type Result<T> = std::result::Result<T, Error>;