Update other language libraries to use new Error struct

This commit is contained in:
Wilson Lin 2020-07-22 21:11:16 +10:00
commit f3ce568005
4 changed files with 11 additions and 11 deletions

View file

@ -1,4 +1,4 @@
use minify_html::{in_place as minify_html_native, Cfg};
use minify_html::{in_place as minify_html_native, Cfg, Error};
use jni::JNIEnv;
use jni::objects::{JByteBuffer, JClass, JObject, JString};
use jni::sys::{jint, jstring};
@ -31,10 +31,10 @@ pub extern "system" fn Java_in_wilsonl_minifyhtml_MinifyHtml_minifyInPlace(
(match minify_html_native(source, &build_cfg(&env, &cfg)) {
Ok(out_len) => out_len,
Err((err, pos)) => {
Err(Error { error_type, position }) => {
env.throw_new(
"in/wilsonl/minifyhtml/MinifyHtml$SyntaxException",
format!("{} [Character {}]", err.message(), pos),
format!("{} [Character {}]", error_type.message(), position),
).unwrap();
0
}
@ -54,10 +54,10 @@ pub extern "system" fn Java_in_wilsonl_minifyhtml_MinifyHtml_minify(
match minify_html_native(&mut code, &build_cfg(&env, &cfg)) {
Ok(out_len) => env.new_string(unsafe { from_utf8_unchecked(&code[0..out_len]) }).unwrap().into_inner(),
Err((err, pos)) => {
Err(Error { error_type, position }) => {
env.throw_new(
"in/wilsonl/minifyhtml/MinifyHtml$SyntaxException",
format!("{} [Character {}]", err.message(), pos),
format!("{} [Character {}]", error_type.message(), position),
).unwrap();
JObject::null().into_inner()
}

View file

@ -1,5 +1,5 @@
use neon::prelude::*;
use minify_html::{Cfg, in_place};
use minify_html::{Cfg, Error, in_place};
fn minify(mut cx: FunctionContext) -> JsResult<JsNumber> {
let mut buffer = cx.argument::<JsBuffer>(0)?;
@ -9,7 +9,7 @@ fn minify(mut cx: FunctionContext) -> JsResult<JsNumber> {
};
match cx.borrow_mut(&mut buffer, |code| in_place(code.as_mut_slice::<u8>(), &cfg)) {
Ok(out_len) => Ok(cx.number(out_len as f64)),
Err((err, pos)) => cx.throw_error(format!("{} [Character {}]", err.message(), pos)),
Err(Error { error_type, position }) => cx.throw_error(format!("{} [Character {}]", error_type.message(), position)),
}
}

View file

@ -1,4 +1,4 @@
use minify_html::{Cfg, in_place as minify_html_native};
use minify_html::{Cfg, Error, in_place as minify_html_native};
use pyo3::prelude::*;
use pyo3::exceptions::SyntaxError;
use pyo3::wrap_pyfunction;
@ -11,7 +11,7 @@ fn minify(code: String, minify_js: bool) -> PyResult<String> {
minify_js,
}) {
Ok(out_len) => Ok(unsafe { from_utf8_unchecked(&code[0..out_len]).to_string() }),
Err((err, pos)) => Err(SyntaxError::py_err(format!("{} [Character {}]", err.message(), pos))),
Err(Error { error_type, position }) => Err(SyntaxError::py_err(format!("{} [Character {}]", error_type.message(), position))),
}
}

View file

@ -1,4 +1,4 @@
use minify_html::{Cfg, in_place as minify_html_native};
use minify_html::{Cfg, Error, in_place as minify_html_native};
use rutie::{Boolean, Class, class, Hash, methods, Object, RString, Symbol, VM};
use std::str::from_utf8_unchecked;
@ -23,7 +23,7 @@ methods! {
};
minify_html_native(&mut code, cfg)
.map_err(|(err, pos)| VM::raise(Class::from_existing("SyntaxError"), format!("{} [Character {}]", err.message(), pos).as_str()))
.map_err(|Error { error_type, position }| VM::raise(Class::from_existing("SyntaxError"), format!("{} [Character {}]", error_type.message(), position).as_str()))
.map(|out_len| RString::new_utf8(unsafe { from_utf8_unchecked(&code[0..out_len]) }))
.unwrap()
}