viewpoint_core/error/
mod.rs

1//! Core error types.
2
3use std::time::Duration;
4use thiserror::Error;
5
6/// Errors that can occur in the core domain.
7#[derive(Error, Debug)]
8pub enum CoreError {
9    /// CDP communication error.
10    #[error("CDP error: {0}")]
11    Cdp(#[from] viewpoint_cdp::CdpError),
12
13    /// Browser error.
14    #[error("browser error: {0}")]
15    Browser(#[from] BrowserError),
16
17    /// Context error.
18    #[error("context error: {0}")]
19    Context(#[from] ContextError),
20
21    /// Page error.
22    #[error("page error: {0}")]
23    Page(#[from] PageError),
24
25    /// Wait error.
26    #[error("wait error: {0}")]
27    Wait(#[from] WaitError),
28
29    /// Navigation error.
30    #[error("navigation error: {0}")]
31    Navigation(#[from] NavigationError),
32
33    /// Locator error.
34    #[error("locator error: {0}")]
35    Locator(#[from] LocatorError),
36
37    /// Network error.
38    #[error("network error: {0}")]
39    Network(#[from] NetworkError),
40}
41
42/// Errors related to browser operations.
43#[derive(Error, Debug)]
44pub enum BrowserError {
45    /// Chromium executable not found.
46    #[error("Chromium not found. Set CHROMIUM_PATH environment variable or install Chromium.")]
47    ChromiumNotFound,
48
49    /// Failed to launch browser process.
50    #[error("failed to launch browser: {0}")]
51    LaunchFailed(String),
52
53    /// Browser launch timed out.
54    #[error("browser launch timeout after {0:?}")]
55    LaunchTimeout(Duration),
56
57    /// Failed to connect to browser.
58    #[error("failed to connect to browser: {0}")]
59    ConnectionFailed(String),
60
61    /// Browser is already closed.
62    #[error("browser is closed")]
63    Closed,
64
65    /// Context error during browser operation.
66    #[error("context error: {0}")]
67    Context(#[from] ContextError),
68
69    /// CDP error during browser operation.
70    #[error("CDP error: {0}")]
71    Cdp(#[from] viewpoint_cdp::CdpError),
72}
73
74/// Errors related to browser context operations.
75#[derive(Error, Debug)]
76pub enum ContextError {
77    /// Context is already closed.
78    #[error("context is closed")]
79    Closed,
80
81    /// Failed to create context.
82    #[error("failed to create context: {0}")]
83    CreateFailed(String),
84
85    /// Internal error.
86    #[error("internal error: {0}")]
87    Internal(String),
88
89    /// Operation timed out.
90    #[error("{operation} timed out after {duration:?}")]
91    Timeout {
92        /// The operation that timed out.
93        operation: String,
94        /// The duration before timeout.
95        duration: Duration,
96    },
97
98    /// CDP error during context operation.
99    #[error("CDP error: {0}")]
100    Cdp(#[from] viewpoint_cdp::CdpError),
101}
102
103/// Errors related to page operations.
104#[derive(Error, Debug)]
105pub enum PageError {
106    /// Page is already closed.
107    #[error("page is closed")]
108    Closed,
109
110    /// Failed to create page.
111    #[error("failed to create page: {0}")]
112    CreateFailed(String),
113
114    /// JavaScript evaluation failed.
115    #[error("evaluation failed: {0}")]
116    EvaluationFailed(String),
117
118    /// CDP error during page operation.
119    #[error("CDP error: {0}")]
120    Cdp(#[from] viewpoint_cdp::CdpError),
121}
122
123/// Errors related to wait operations.
124#[derive(Error, Debug)]
125pub enum WaitError {
126    /// Wait operation timed out.
127    #[error("timeout after {0:?}")]
128    Timeout(Duration),
129
130    /// Wait operation was cancelled.
131    #[error("wait cancelled")]
132    Cancelled,
133
134    /// Page was closed during wait.
135    #[error("page closed during wait")]
136    PageClosed,
137}
138
139/// Errors related to navigation operations.
140#[derive(Error, Debug)]
141pub enum NavigationError {
142    /// Navigation timed out.
143    #[error("navigation timeout after {0:?}")]
144    Timeout(Duration),
145
146    /// Network error during navigation.
147    #[error("network error: {0}")]
148    NetworkError(String),
149
150    /// SSL certificate error.
151    #[error("SSL error: {0}")]
152    SslError(String),
153
154    /// Navigation was cancelled.
155    #[error("navigation cancelled")]
156    Cancelled,
157
158    /// CDP error during navigation.
159    #[error("CDP error: {0}")]
160    Cdp(#[from] viewpoint_cdp::CdpError),
161
162    /// Wait error during navigation.
163    #[error("wait error: {0}")]
164    Wait(#[from] WaitError),
165}
166
167/// Errors related to locator operations.
168#[derive(Error, Debug)]
169pub enum LocatorError {
170    /// Element not found.
171    #[error("element not found: {0}")]
172    NotFound(String),
173
174    /// Multiple elements found when expecting one.
175    #[error("strict mode violation: {0} elements found, expected 1")]
176    StrictModeViolation(usize),
177
178    /// Element is not visible.
179    #[error("element is not visible")]
180    NotVisible,
181
182    /// Element is not enabled.
183    #[error("element is not enabled")]
184    NotEnabled,
185
186    /// Element is not editable.
187    #[error("element is not editable")]
188    NotEditable,
189
190    /// Operation timed out.
191    #[error("timeout after {0:?}")]
192    Timeout(Duration),
193
194    /// JavaScript evaluation error.
195    #[error("evaluation error: {0}")]
196    EvaluationError(String),
197
198    /// CDP error during locator operation.
199    #[error("CDP error: {0}")]
200    Cdp(#[from] viewpoint_cdp::CdpError),
201
202    /// Page is closed.
203    #[error("page is closed")]
204    PageClosed,
205
206    /// Touch not enabled.
207    #[error("touch not enabled: call page.enable_touch() or set hasTouch: true in browser context options before using touch actions")]
208    TouchNotEnabled,
209}
210
211/// Errors related to network operations.
212#[derive(Error, Debug)]
213pub enum NetworkError {
214    /// Route has already been handled.
215    #[error("route has already been handled")]
216    AlreadyHandled,
217
218    /// Invalid response data.
219    #[error("invalid response: {0}")]
220    InvalidResponse(String),
221
222    /// Request was aborted.
223    #[error("request aborted")]
224    Aborted,
225
226    /// Request timed out.
227    #[error("request timeout after {0:?}")]
228    Timeout(Duration),
229
230    /// No matching request/response found.
231    #[error("no matching request/response found")]
232    NotFound,
233
234    /// IO error.
235    #[error("IO error: {0}")]
236    IoError(String),
237
238    /// HAR parsing error.
239    #[error("HAR error: {0}")]
240    HarError(String),
241
242    /// CDP error during network operation.
243    #[error("CDP error: {0}")]
244    Cdp(#[from] viewpoint_cdp::CdpError),
245}