pebbles 0.0.103

The Worst Web Automation Framework Ever. (╯°□°)╯︵ ┻━┻
Documentation
use std::borrow::Cow;
use std::backtrace::Backtrace;
use serde_json::json;

#[derive(Debug)]
#[non_exhaustive]
#[allow(missing_docs)]
pub enum PebblesError {
    WebDriverError(PebblesErrorDetails),
    NewSessionError(PebblesErrorDetails),
    ElementStaleError(PebblesErrorDetails),
    NoElementsError(PebblesErrorDetails),
    NoWindowError(PebblesErrorDetails),
    NotInViewportError(PebblesErrorDetails),
    RequestError(PebblesErrorDetails),
    PhrasingError(PebblesErrorDetails),
    TimeoutError(PebblesErrorDetails),
    MathError(PebblesErrorDetails),
    ProxyError(PebblesErrorDetails),
}

#[derive(Debug)]
pub struct PebblesErrorDetails {
    pub message: Cow<'static, str>,
    pub stacktrace: String,
    pub data: serde_json::Value,
}

impl PebblesErrorDetails {
    /// Create a new `PebblesErrorDetails`.
    pub fn new(message: impl Into<Cow<'static, str>>) -> Self {
        Self {
            message: message.into(),
            stacktrace: Backtrace::capture().to_string(),
            data: json!({}),
        }
    }
}

impl From<reqwest::Error> for PebblesError {
    fn from(e:reqwest::Error) -> PebblesError {
        PebblesError::RequestError(
            PebblesErrorDetails::new(format!("{:?}", e))
        )
    }
}