mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-16 15:40:02 -04:00
rewrite
This commit is contained in:
parent
00de00e7ca
commit
cb2ab0cedd
36 changed files with 1825 additions and 1355 deletions
49
rewriter/wasm/src/error.rs
Normal file
49
rewriter/wasm/src/error.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
use js_sys::Error;
|
||||
use rewriter::RewriterError as InnerRewriterError;
|
||||
use thiserror::Error;
|
||||
use wasm_bindgen::{JsError, JsValue};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum RewriterError {
|
||||
#[error("JS: {0}")]
|
||||
Js(String),
|
||||
#[error("URL parse error: {0}")]
|
||||
Url(#[from] url::ParseError),
|
||||
#[error("str fromutf8 error: {0}")]
|
||||
Str(#[from] std::str::Utf8Error),
|
||||
#[error("Rewriter: {0}")]
|
||||
Rewriter(#[from] InnerRewriterError),
|
||||
#[error("reflect set failed: {0}")]
|
||||
ReflectSetFail(String),
|
||||
|
||||
#[error("{0} was not {1}")]
|
||||
Not(String, &'static str),
|
||||
}
|
||||
|
||||
impl From<JsValue> for RewriterError {
|
||||
fn from(value: JsValue) -> Self {
|
||||
Self::Js(Error::from(value).to_string().into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RewriterError> for JsValue {
|
||||
fn from(value: RewriterError) -> Self {
|
||||
JsError::from(value).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl RewriterError {
|
||||
pub fn not_str(x: &str) -> Self {
|
||||
Self::Not(x.to_string(), "string")
|
||||
}
|
||||
|
||||
pub fn not_fn(x: &str) -> Self {
|
||||
Self::Not(x.to_string(), "function")
|
||||
}
|
||||
|
||||
pub fn not_bool(x: &str) -> Self {
|
||||
Self::Not(x.to_string(), "bool")
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, RewriterError>;
|
Loading…
Add table
Add a link
Reference in a new issue