use std::io::ErrorKind;
use tao::{
error::{ExternalError, OsError},
event_loop::EventLoopClosed,
};
use thiserror::Error;
use wry::Error as WryError;
pub type PuppeteerResult<T> = Result<T, PuppeteerError>;
#[derive(Debug, Error)]
pub enum PuppeteerError {
#[error("An error occurred while initializing the app")]
AppInit(String),
#[error("The error that is returned when an EventLoopProxy attempts to wake up an EventLoop that no longer exists. Contains the original event given to send_event.
")]
TaoEventLoopClosed,
#[error("An error whose cause it outside the control of the running app")]
TaoExternal(String),
#[error("The error type for when the OS cannot perform the requested operation")]
TaoOsError(String),
#[error("Errors returned by wry")]
Wry(WryError),
#[error("Unable to detect current monitor")]
UnableToDetectCurrentMonitor,
#[error("Unable to detect primary monitor")]
UnableToDetectPrimaryMonitor,
#[error("The `WebView` was not found")]
WebViewDoesNotExist,
#[error("The `window is not resizable")]
WindowIsNotResizable,
#[error("Represents std::io::ErrorKind")]
Io(ErrorKind),
#[error("The font detected ({0:?}) is not a valid `WOFF2` format for the web.")]
InvalidFontExpectedWoff2(String),
#[error("Tried to get a file name without the extension part using `Path::file_stem()` but the file stem does not exist")]
InvalidFileStemName,
#[error("The maximum size set for the resource has been exceeded")]
MaxResourceLengthExceeded,
#[error("Encountered a GTK error on Linux")]
GtkError,
#[error("String must be less than 2MiB on Windows OS")]
StringTooLarge,
}
impl From<std::io::Error> for PuppeteerError {
fn from(error: std::io::Error) -> Self {
PuppeteerError::Io(error.kind())
}
}
impl<T> From<EventLoopClosed<T>> for PuppeteerError {
fn from(_: EventLoopClosed<T>) -> Self {
PuppeteerError::TaoEventLoopClosed
}
}
impl From<ExternalError> for PuppeteerError {
fn from(value: ExternalError) -> Self {
PuppeteerError::TaoExternal(value.to_string())
}
}
impl From<WryError> for PuppeteerError {
fn from(value: WryError) -> Self {
PuppeteerError::Wry(value)
}
}
impl From<OsError> for PuppeteerError {
fn from(value: OsError) -> Self {
PuppeteerError::TaoOsError(value.to_string())
}
}