viewpoint_core/
error.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
38/// Errors related to browser operations.
39#[derive(Error, Debug)]
40pub enum BrowserError {
41    /// Chromium executable not found.
42    #[error("Chromium not found. Set CHROMIUM_PATH environment variable or install Chromium.")]
43    ChromiumNotFound,
44
45    /// Failed to launch browser process.
46    #[error("failed to launch browser: {0}")]
47    LaunchFailed(String),
48
49    /// Browser launch timed out.
50    #[error("browser launch timeout after {0:?}")]
51    LaunchTimeout(Duration),
52
53    /// Failed to connect to browser.
54    #[error("failed to connect to browser: {0}")]
55    ConnectionFailed(String),
56
57    /// Browser is already closed.
58    #[error("browser is closed")]
59    Closed,
60
61    /// CDP error during browser operation.
62    #[error("CDP error: {0}")]
63    Cdp(#[from] viewpoint_cdp::CdpError),
64}
65
66/// Errors related to browser context operations.
67#[derive(Error, Debug)]
68pub enum ContextError {
69    /// Context is already closed.
70    #[error("context is closed")]
71    Closed,
72
73    /// Failed to create context.
74    #[error("failed to create context: {0}")]
75    CreateFailed(String),
76
77    /// CDP error during context operation.
78    #[error("CDP error: {0}")]
79    Cdp(#[from] viewpoint_cdp::CdpError),
80}
81
82/// Errors related to page operations.
83#[derive(Error, Debug)]
84pub enum PageError {
85    /// Page is already closed.
86    #[error("page is closed")]
87    Closed,
88
89    /// Failed to create page.
90    #[error("failed to create page: {0}")]
91    CreateFailed(String),
92
93    /// JavaScript evaluation failed.
94    #[error("evaluation failed: {0}")]
95    EvaluationFailed(String),
96
97    /// CDP error during page operation.
98    #[error("CDP error: {0}")]
99    Cdp(#[from] viewpoint_cdp::CdpError),
100}
101
102/// Errors related to wait operations.
103#[derive(Error, Debug)]
104pub enum WaitError {
105    /// Wait operation timed out.
106    #[error("timeout after {0:?}")]
107    Timeout(Duration),
108
109    /// Wait operation was cancelled.
110    #[error("wait cancelled")]
111    Cancelled,
112
113    /// Page was closed during wait.
114    #[error("page closed during wait")]
115    PageClosed,
116}
117
118/// Errors related to navigation operations.
119#[derive(Error, Debug)]
120pub enum NavigationError {
121    /// Navigation timed out.
122    #[error("navigation timeout after {0:?}")]
123    Timeout(Duration),
124
125    /// Network error during navigation.
126    #[error("network error: {0}")]
127    NetworkError(String),
128
129    /// SSL certificate error.
130    #[error("SSL error: {0}")]
131    SslError(String),
132
133    /// Navigation was cancelled.
134    #[error("navigation cancelled")]
135    Cancelled,
136
137    /// CDP error during navigation.
138    #[error("CDP error: {0}")]
139    Cdp(#[from] viewpoint_cdp::CdpError),
140
141    /// Wait error during navigation.
142    #[error("wait error: {0}")]
143    Wait(#[from] WaitError),
144}
145
146/// Errors related to locator operations.
147#[derive(Error, Debug)]
148pub enum LocatorError {
149    /// Element not found.
150    #[error("element not found: {0}")]
151    NotFound(String),
152
153    /// Multiple elements found when expecting one.
154    #[error("strict mode violation: {0} elements found, expected 1")]
155    StrictModeViolation(usize),
156
157    /// Element is not visible.
158    #[error("element is not visible")]
159    NotVisible,
160
161    /// Element is not enabled.
162    #[error("element is not enabled")]
163    NotEnabled,
164
165    /// Element is not editable.
166    #[error("element is not editable")]
167    NotEditable,
168
169    /// Operation timed out.
170    #[error("timeout after {0:?}")]
171    Timeout(Duration),
172
173    /// JavaScript evaluation error.
174    #[error("evaluation error: {0}")]
175    EvaluationError(String),
176
177    /// CDP error during locator operation.
178    #[error("CDP error: {0}")]
179    Cdp(#[from] viewpoint_cdp::CdpError),
180
181    /// Page is closed.
182    #[error("page is closed")]
183    PageClosed,
184}