1use std::fmt;
2
3#[derive(Debug)]
4pub enum CdpError {
5 WebSocket(Box<tokio_tungstenite::tungstenite::Error>),
6 Http(reqwest::Error),
7 Json(serde_json::Error),
8 Io(std::io::Error),
9 InvalidUrl(String),
10 Protocol(String),
11 Timeout,
12 NoTarget,
13}
14
15impl fmt::Display for CdpError {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 match self {
18 CdpError::WebSocket(e) => write!(f, "WebSocket error: {e}"),
19 CdpError::Http(e) => write!(f, "HTTP error: {e}"),
20 CdpError::Json(e) => write!(f, "JSON error: {e}"),
21 CdpError::Io(e) => write!(f, "IO error: {e}"),
22 CdpError::InvalidUrl(s) => write!(f, "Invalid URL: {s}"),
23 CdpError::Protocol(s) => write!(f, "Protocol error: {s}"),
24 CdpError::Timeout => write!(f, "Operation timed out"),
25 CdpError::NoTarget => write!(f, "No page target available"),
26 }
27 }
28}
29
30impl std::error::Error for CdpError {}
31
32impl From<tokio_tungstenite::tungstenite::Error> for CdpError {
33 fn from(e: tokio_tungstenite::tungstenite::Error) -> Self {
34 CdpError::WebSocket(Box::new(e))
35 }
36}
37
38impl From<reqwest::Error> for CdpError {
39 fn from(e: reqwest::Error) -> Self {
40 CdpError::Http(e)
41 }
42}
43
44impl From<serde_json::Error> for CdpError {
45 fn from(e: serde_json::Error) -> Self {
46 CdpError::Json(e)
47 }
48}
49
50impl From<std::io::Error> for CdpError {
51 fn from(e: std::io::Error) -> Self {
52 CdpError::Io(e)
53 }
54}
55
56pub type Result<T> = std::result::Result<T, CdpError>;