Skip to main content

chrome_for_testing/
error.rs

1use rootcause::{Report, ReportConversion, markers};
2use std::borrow::Cow;
3use thiserror::Error;
4
5/// Errors that can occur when using this crate.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// A URL could not be parsed.
9    #[error("URL parse error: {0}")]
10    UrlParsing(#[from] url::ParseError),
11
12    /// An HTTP request failed.
13    #[error("HTTP request failed: {0}")]
14    Request(#[from] reqwest::Error),
15
16    /// The current platform is not supported by `chrome-for-testing`.
17    #[error("Platform (os: {os}, arch: {arch}) is not supported.")]
18    UnsupportedPlatform {
19        /// The operating system name, e.g. "linux".
20        os: Cow<'static, str>,
21
22        /// The system architecture name, e.g. "`x86_64`".
23        arch: Cow<'static, str>,
24    },
25}
26
27impl<T> ReportConversion<url::ParseError, markers::Mutable, T> for Error
28where
29    Error: markers::ObjectMarkerFor<T>,
30{
31    fn convert_report(
32        report: Report<url::ParseError, markers::Mutable, T>,
33    ) -> Report<Self, markers::Mutable, T> {
34        report.context_transform(Error::UrlParsing)
35    }
36}
37
38impl<T> ReportConversion<reqwest::Error, markers::Mutable, T> for Error
39where
40    Error: markers::ObjectMarkerFor<T>,
41{
42    fn convert_report(
43        report: Report<reqwest::Error, markers::Mutable, T>,
44    ) -> Report<Self, markers::Mutable, T> {
45        report.context_transform(Error::Request)
46    }
47}