use std::time::Duration;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum CoreError {
#[error("CDP error: {0}")]
Cdp(#[from] viewpoint_cdp::CdpError),
#[error("browser error: {0}")]
Browser(#[from] BrowserError),
#[error("context error: {0}")]
Context(#[from] ContextError),
#[error("page error: {0}")]
Page(#[from] PageError),
#[error("wait error: {0}")]
Wait(#[from] WaitError),
#[error("navigation error: {0}")]
Navigation(#[from] NavigationError),
#[error("locator error: {0}")]
Locator(#[from] LocatorError),
#[error("network error: {0}")]
Network(#[from] NetworkError),
}
#[derive(Error, Debug)]
pub enum BrowserError {
#[error("Chromium not found. Set CHROMIUM_PATH environment variable or install Chromium.")]
ChromiumNotFound,
#[error("failed to launch browser: {0}")]
LaunchFailed(String),
#[error("browser launch timeout after {0:?}")]
LaunchTimeout(Duration),
#[error("failed to connect to browser: {0}")]
ConnectionFailed(String),
#[error("connection timeout after {0:?}")]
ConnectionTimeout(Duration),
#[error("invalid endpoint URL: {0}")]
InvalidEndpointUrl(String),
#[error("endpoint discovery failed: {0}")]
EndpointDiscoveryFailed(String),
#[error("browser is closed")]
Closed,
#[error("context error: {0}")]
Context(#[from] ContextError),
#[error("CDP error: {0}")]
Cdp(#[from] viewpoint_cdp::CdpError),
}
#[derive(Error, Debug)]
pub enum ContextError {
#[error("context is closed")]
Closed,
#[error("failed to create context: {0}")]
CreateFailed(String),
#[error("internal error: {0}")]
Internal(String),
#[error("{operation} timed out after {duration:?}")]
Timeout {
operation: String,
duration: Duration,
},
#[error("CDP error: {0}")]
Cdp(#[from] viewpoint_cdp::CdpError),
}
#[derive(Error, Debug)]
pub enum PageError {
#[error("page is closed")]
Closed,
#[error("failed to create page: {0}")]
CreateFailed(String),
#[error("evaluation failed: {0}")]
EvaluationFailed(String),
#[error("CDP error: {0}")]
Cdp(#[from] viewpoint_cdp::CdpError),
}
#[derive(Error, Debug)]
pub enum WaitError {
#[error("timeout after {0:?}")]
Timeout(Duration),
#[error("wait cancelled")]
Cancelled,
#[error("page closed during wait")]
PageClosed,
}
#[derive(Error, Debug)]
pub enum NavigationError {
#[error("navigation timeout after {0:?}")]
Timeout(Duration),
#[error("network error: {0}")]
NetworkError(String),
#[error("SSL error: {0}")]
SslError(String),
#[error("navigation cancelled")]
Cancelled,
#[error("CDP error: {0}")]
Cdp(#[from] viewpoint_cdp::CdpError),
#[error("wait error: {0}")]
Wait(#[from] WaitError),
}
#[derive(Error, Debug)]
pub enum LocatorError {
#[error("element not found: {0}")]
NotFound(String),
#[error("strict mode violation: {0} elements found, expected 1")]
StrictModeViolation(usize),
#[error("element is not visible")]
NotVisible,
#[error("element is not enabled")]
NotEnabled,
#[error("element is not editable")]
NotEditable,
#[error("timeout after {0:?}")]
Timeout(Duration),
#[error("evaluation error: {0}")]
EvaluationError(String),
#[error("CDP error: {0}")]
Cdp(#[from] viewpoint_cdp::CdpError),
#[error("page is closed")]
PageClosed,
#[error(
"touch not enabled: call page.enable_touch() or set hasTouch: true in browser context options before using touch actions"
)]
TouchNotEnabled,
#[error("wait error: {0}")]
WaitError(#[from] WaitError),
}
#[derive(Error, Debug)]
pub enum NetworkError {
#[error("route has already been handled")]
AlreadyHandled,
#[error("invalid response: {0}")]
InvalidResponse(String),
#[error("request aborted")]
Aborted,
#[error("request timeout after {0:?}")]
Timeout(Duration),
#[error("no matching request/response found")]
NotFound,
#[error("IO error: {0}")]
IoError(String),
#[error("HAR error: {0}")]
HarError(String),
#[error("CDP error: {0}")]
Cdp(#[from] viewpoint_cdp::CdpError),
}