use serde_json::Value;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error)]
pub enum Error {
#[error("browser launch failed: {0}")]
LaunchFailed(String),
#[error("connection failed: {0}")]
ConnectionFailed(String),
#[error("transport error: {0}")]
TransportError(String),
#[error("protocol error: {0}")]
ProtocolError(String),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error("timeout: {0}")]
Timeout(String),
#[error("navigation to {url} timed out after {duration_ms}ms")]
NavigationTimeout { url: String, duration_ms: u64 },
#[error("target closed: {target_type} ({context})")]
TargetClosed { target_type: String, context: String },
#[error("element not found: {0}")]
ElementNotFound(String),
#[error("channel closed")]
ChannelClosed,
#[error("invalid argument: {0}")]
InvalidArgument(String),
#[error("CDP error {code}: {message}")]
CdpError {
code: i64,
message: String,
#[allow(dead_code)]
data: Option<Value>,
},
#[error("not yet implemented: {0}")]
NotImplemented(&'static str),
#[error("http error: {0}")]
Http(String),
#[error("{0}: {1}")]
Context(String, Box<Error>),
}
impl Error {
pub fn context(self, msg: impl Into<String>) -> Self {
Error::Context(msg.into(), Box::new(self))
}
}