use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error)]
pub enum Error {
#[error("Failed to launch Chrome: {0}")]
Launch(String),
#[error("Transport error: {context}")]
Transport {
context: String,
#[source]
source: Option<std::io::Error>,
},
#[error("CDP error in {method}: {message} (code {code})")]
Cdp {
method: String,
code: i64,
message: String,
},
#[error("CDP error: {0}")]
CdpSimple(String),
#[error("Navigation error: {0}")]
Navigation(String),
#[error("Element not found: {0}")]
ElementNotFound(String),
#[error("Element not visible: '{selector}' exists in DOM but is not rendered (hidden, display:none, or off-screen)")]
ElementNotVisible { selector: String },
#[error("Timeout: {0}")]
Timeout(String),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Decode error: {0}")]
Decode(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Chrome not found")]
ChromeNotFound,
#[error("Patching error in {operation}: {message}")]
Patching { operation: String, message: String },
#[error("Retry exhausted after {attempts} attempts: {last_error}")]
RetryExhausted { attempts: u32, last_error: String },
}
impl Error {
pub fn transport(context: impl Into<String>) -> Self {
Self::Transport {
context: context.into(),
source: None,
}
}
pub fn transport_io(context: impl Into<String>, source: std::io::Error) -> Self {
Self::Transport {
context: context.into(),
source: Some(source),
}
}
pub fn cdp(method: impl Into<String>, code: i64, message: impl Into<String>) -> Self {
Self::Cdp {
method: method.into(),
code,
message: message.into(),
}
}
pub fn patching(operation: impl Into<String>, message: impl Into<String>) -> Self {
Self::Patching {
operation: operation.into(),
message: message.into(),
}
}
}