pebbles 0.0.101

A unfinished webautomation framework for working with Firefox and the geckodriver.
Documentation
use std::borrow::Cow;
use std::backtrace::Backtrace;

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

#[derive(Debug)]
pub struct PebblesErrorDetails {
    pub message: Cow<'static, str>,
    pub stacktrace: String,
    pub data: Option<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: None,
        }
    }
}

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