1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, Error)]
10pub enum Error {
11 #[error("Failed to launch Chrome: {0}")]
13 Launch(String),
14
15 #[error("Transport error: {context}")]
17 Transport {
18 context: String,
19 #[source]
20 source: Option<std::io::Error>,
21 },
22
23 #[error("CDP error in {method}: {message} (code {code})")]
25 Cdp {
26 method: String,
27 code: i64,
28 message: String,
29 },
30
31 #[error("CDP error: {0}")]
33 CdpSimple(String),
34
35 #[error("Navigation error: {0}")]
37 Navigation(String),
38
39 #[error("Element not found: {0}")]
41 ElementNotFound(String),
42
43 #[error("Element not visible: '{selector}' exists in DOM but is not rendered (hidden, display:none, or off-screen)")]
45 ElementNotVisible { selector: String },
46
47 #[error("Timeout: {0}")]
49 Timeout(String),
50
51 #[error("Serialization error: {0}")]
53 Serialization(#[from] serde_json::Error),
54
55 #[error("Decode error: {0}")]
57 Decode(String),
58
59 #[error("IO error: {0}")]
61 Io(#[from] std::io::Error),
62
63 #[error("Chrome not found")]
65 ChromeNotFound,
66
67 #[error("Patching error in {operation}: {message}")]
69 Patching { operation: String, message: String },
70
71 #[error("Retry exhausted after {attempts} attempts: {last_error}")]
73 RetryExhausted { attempts: u32, last_error: String },
74}
75
76impl Error {
77 pub fn transport(context: impl Into<String>) -> Self {
79 Self::Transport {
80 context: context.into(),
81 source: None,
82 }
83 }
84
85 pub fn transport_io(context: impl Into<String>, source: std::io::Error) -> Self {
87 Self::Transport {
88 context: context.into(),
89 source: Some(source),
90 }
91 }
92
93 pub fn cdp(method: impl Into<String>, code: i64, message: impl Into<String>) -> Self {
95 Self::Cdp {
96 method: method.into(),
97 code,
98 message: message.into(),
99 }
100 }
101
102 pub fn patching(operation: impl Into<String>, message: impl Into<String>) -> Self {
104 Self::Patching {
105 operation: operation.into(),
106 message: message.into(),
107 }
108 }
109}