1use serde_json::Value;
4use thiserror::Error;
5
6pub type Result<T> = std::result::Result<T, Error>;
8
9#[derive(Debug, Error)]
14pub enum Error {
15 #[error("browser launch failed: {0}")]
16 LaunchFailed(String),
17
18 #[error("connection failed: {0}")]
19 ConnectionFailed(String),
20
21 #[error("transport error: {0}")]
22 TransportError(String),
23
24 #[error("protocol error: {0}")]
25 ProtocolError(String),
26
27 #[error(transparent)]
28 Io(#[from] std::io::Error),
29
30 #[error(transparent)]
31 Json(#[from] serde_json::Error),
32
33 #[error("timeout: {0}")]
34 Timeout(String),
35
36 #[error("navigation to {url} timed out after {duration_ms}ms")]
37 NavigationTimeout { url: String, duration_ms: u64 },
38
39 #[error("target closed: {target_type} ({context})")]
40 TargetClosed { target_type: String, context: String },
41
42 #[error("element not found: {0}")]
43 ElementNotFound(String),
44
45 #[error("channel closed")]
46 ChannelClosed,
47
48 #[error("invalid argument: {0}")]
49 InvalidArgument(String),
50
51 #[error("CDP error {code}: {message}")]
53 CdpError {
54 code: i64,
55 message: String,
56 #[allow(dead_code)]
57 data: Option<Value>,
58 },
59
60 #[error("not yet implemented: {0}")]
62 NotImplemented(&'static str),
63
64 #[error("http error: {0}")]
65 Http(String),
66
67 #[error("{0}: {1}")]
69 Context(String, Box<Error>),
70}
71
72impl Error {
73 pub fn context(self, msg: impl Into<String>) -> Self {
75 Error::Context(msg.into(), Box::new(self))
76 }
77}