viewpoint_cdp/error/
mod.rs1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum CdpError {
8 #[error("WebSocket connection failed: {0}")]
10 ConnectionFailed(String),
11
12 #[error("WebSocket connection lost")]
14 ConnectionLost,
15
16 #[error("failed to send CDP message: {0}")]
18 SendFailed(String),
19
20 #[error("CDP protocol error {code}: {message}")]
22 Protocol { code: i64, message: String },
23
24 #[error("JSON error: {0}")]
26 Json(#[from] serde_json::Error),
27
28 #[error("response timeout after {0:?}")]
30 Timeout(std::time::Duration),
31
32 #[error("invalid message ID: expected {expected}, got {got}")]
34 InvalidMessageId { expected: u64, got: u64 },
35
36 #[error("invalid WebSocket URL: {0}")]
38 InvalidUrl(String),
39
40 #[error("session not found: {0}")]
42 SessionNotFound(String),
43
44 #[error("failed to spawn browser process: {0}")]
46 SpawnFailed(String),
47
48 #[error("failed to get debugging URL from browser")]
50 NoDebuggingUrl,
51
52 #[error(
54 "Chromium not found. Set CHROMIUM_PATH environment variable or ensure Chromium is installed."
55 )]
56 ChromiumNotFound,
57
58 #[error("browser launch timeout after {0:?}")]
60 LaunchTimeout(std::time::Duration),
61
62 #[error("connection timeout after {0:?}")]
64 ConnectionTimeout(std::time::Duration),
65
66 #[error("failed to discover WebSocket endpoint from {url}: {reason}")]
68 EndpointDiscoveryFailed { url: String, reason: String },
69
70 #[error("invalid endpoint URL: {0}")]
72 InvalidEndpointUrl(String),
73
74 #[error("HTTP request failed: {0}")]
76 HttpRequestFailed(String),
77}
78
79impl From<tokio_tungstenite::tungstenite::Error> for CdpError {
80 fn from(err: tokio_tungstenite::tungstenite::Error) -> Self {
81 match err {
82 tokio_tungstenite::tungstenite::Error::ConnectionClosed
83 | tokio_tungstenite::tungstenite::Error::AlreadyClosed => Self::ConnectionLost,
84 other => Self::ConnectionFailed(other.to_string()),
85 }
86 }
87}
88
89#[cfg(test)]
90mod tests;