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    /// Connection timed out.
62    #[error("connection timeout after {0:?}")]
63    ConnectionTimeout(Duration),
64
65    /// Invalid endpoint URL.
66    #[error("invalid endpoint URL: {0}")]
67    InvalidEndpointUrl(String),
68
69    /// Failed to discover WebSocket endpoint from HTTP endpoint.
70    #[error("endpoint discovery failed: {0}")]
71    EndpointDiscoveryFailed(String),
72
73    /// Browser is already closed.
74    #[error("browser is closed")]
75    Closed,
76
77    /// Context error during browser operation.
78    #[error("context error: {0}")]
79    Context(#[from] ContextError),
80
81    /// CDP error during browser operation.
82    #[error("CDP error: {0}")]
83    Cdp(#[from] viewpoint_cdp::CdpError),
84}
85
86/// Errors related to browser context operations.
87#[derive(Error, Debug)]
88pub enum ContextError {
89    /// Context is already closed.
90    #[error("context is closed")]
91    Closed,
92
93    /// Failed to create context.
94    #[error("failed to create context: {0}")]
95    CreateFailed(String),
96
97    /// Internal error.
98    #[error("internal error: {0}")]
99    Internal(String),
100
101    /// Operation timed out.
102    #[error("{operation} timed out after {duration:?}")]
103    Timeout {
104        /// The operation that timed out.
105        operation: String,
106        /// The duration before timeout.
107        duration: Duration,
108    },
109
110    /// CDP error during context operation.
111    #[error("CDP error: {0}")]
112    Cdp(#[from] viewpoint_cdp::CdpError),
113}
114
115/// Errors related to page operations.
116#[derive(Error, Debug)]
117pub enum PageError {
118    /// Page is already closed.
119    #[error("page is closed")]
120    Closed,
121
122    /// Failed to create page.
123    #[error("failed to create page: {0}")]
124    CreateFailed(String),
125
126    /// JavaScript evaluation failed.
127    #[error("evaluation failed: {0}")]
128    EvaluationFailed(String),
129
130    /// CDP error during page operation.
131    #[error("CDP error: {0}")]
132    Cdp(#[from] viewpoint_cdp::CdpError),
133}
134
135/// Errors related to wait operations.
136#[derive(Error, Debug)]
137pub enum WaitError {
138    /// Wait operation timed out.
139    #[error("timeout after {0:?}")]
140    Timeout(Duration),
141
142    /// Wait operation was cancelled.
143    #[error("wait cancelled")]
144    Cancelled,
145
146    /// Page was closed during wait.
147    #[error("page closed during wait")]
148    PageClosed,
149}
150
151/// Errors related to navigation operations.
152#[derive(Error, Debug)]
153pub enum NavigationError {
154    /// Navigation timed out.
155    #[error("navigation timeout after {0:?}")]
156    Timeout(Duration),
157
158    /// Network error during navigation.
159    #[error("network error: {0}")]
160    NetworkError(String),
161
162    /// SSL certificate error.
163    #[error("SSL error: {0}")]
164    SslError(String),
165
166    /// Navigation was cancelled.
167    #[error("navigation cancelled")]
168    Cancelled,
169
170    /// CDP error during navigation.
171    #[error("CDP error: {0}")]
172    Cdp(#[from] viewpoint_cdp::CdpError),
173
174    /// Wait error during navigation.
175    #[error("wait error: {0}")]
176    Wait(#[from] WaitError),
177}
178
179/// Errors related to locator operations.
180#[derive(Error, Debug)]
181pub enum LocatorError {
182    /// Element not found.
183    #[error("element not found: {0}")]
184    NotFound(String),
185
186    /// Multiple elements found when expecting one.
187    #[error("strict mode violation: {0} elements found, expected 1")]
188    StrictModeViolation(usize),
189
190    /// Element is not visible.
191    #[error("element is not visible")]
192    NotVisible,
193
194    /// Element is not enabled.
195    #[error("element is not enabled")]
196    NotEnabled,
197
198    /// Element is not editable.
199    #[error("element is not editable")]
200    NotEditable,
201
202    /// Operation timed out.
203    #[error("timeout after {0:?}")]
204    Timeout(Duration),
205
206    /// JavaScript evaluation error.
207    #[error("evaluation error: {0}")]
208    EvaluationError(String),
209
210    /// CDP error during locator operation.
211    #[error("CDP error: {0}")]
212    Cdp(#[from] viewpoint_cdp::CdpError),
213
214    /// Page is closed.
215    #[error("page is closed")]
216    PageClosed,
217
218    /// Touch not enabled.
219    #[error(
220        "touch not enabled: call page.enable_touch() or set hasTouch: true in browser context options before using touch actions"
221    )]
222    TouchNotEnabled,
223}
224
225/// Errors related to network operations.
226#[derive(Error, Debug)]
227pub enum NetworkError {
228    /// Route has already been handled.
229    #[error("route has already been handled")]
230    AlreadyHandled,
231
232    /// Invalid response data.
233    #[error("invalid response: {0}")]
234    InvalidResponse(String),
235
236    /// Request was aborted.
237    #[error("request aborted")]
238    Aborted,
239
240    /// Request timed out.
241    #[error("request timeout after {0:?}")]
242    Timeout(Duration),
243
244    /// No matching request/response found.
245    #[error("no matching request/response found")]
246    NotFound,
247
248    /// IO error.
249    #[error("IO error: {0}")]
250    IoError(String),
251
252    /// HAR parsing error.
253    #[error("HAR error: {0}")]
254    HarError(String),
255
256    /// CDP error during network operation.
257    #[error("CDP error: {0}")]
258    Cdp(#[from] viewpoint_cdp::CdpError),
259}