Skip to main content

rightkit_browser/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum BrowserError {
5    #[error("no Chrome, Chromium, or Edge executable found")]
6    ChromeNotFound,
7    /// Chrome for Testing was not found (or an explicit path is missing); carries what was
8    /// searched and how to install it.
9    #[error("Chrome for Testing not found: {0}")]
10    ChromeForTestingNotFound(String),
11    #[error("launch failed: {0}")]
12    Launch(String),
13    #[error("profile error: {0}")]
14    Profile(String),
15    #[error("profile '{0}' is already in use by another session")]
16    ProfileInUse(String),
17    #[error("cdp error: {0}")]
18    Cdp(String),
19    #[error("stale or foreign ref '{0}'; observe again before acting")]
20    StaleRef(String),
21    #[error("no element matched '{0}'")]
22    NoElement(String),
23    #[error("selector '{0}' is ambiguous ({1} matches)")]
24    Ambiguous(String, u64),
25    #[error("element '{0}' is not visible or has no box")]
26    NotInteractable(String),
27    #[error("unknown page '{0}'")]
28    UnknownPage(String),
29    #[error("unknown key '{0}'")]
30    UnknownKey(String),
31    #[error("timed out: {0}")]
32    Timeout(String),
33    #[error("invalid argument: {0}")]
34    Invalid(String),
35    /// The caller's admission hook refused the effect before it happened.
36    #[error("denied before effect: {0}")]
37    Denied(String),
38    /// The network (SSRF/host) policy refused a URL before any request left the machine.
39    #[error("blocked by network policy: {0}")]
40    Blocked(crate::policy::PolicyDenial),
41    #[error("io: {0}")]
42    Io(#[from] std::io::Error),
43}
44
45pub type Result<T> = std::result::Result<T, BrowserError>;
46
47pub(crate) fn cdp<E: std::fmt::Display>(e: E) -> BrowserError {
48    BrowserError::Cdp(e.to_string())
49}