Skip to content

Commit

Permalink
[Node.js] Improve invalid arugment type error messages (fixes #101)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonzlin committed Jan 5, 2023
1 parent 9eeca7b commit 02ba438
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Use FxHasher for internal hash-based data structures.
- Bump [css-minify](https://github.com/Mnwa/css-minify) to 0.3.1.
- [WASM] Add `type` and `main` fields to package.json.
- [Node.js] Improve invalid argument type error messages.

## 0.10.3

Expand Down
8 changes: 6 additions & 2 deletions nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ use neon::prelude::*;
use neon::types::buffer::TypedArray;

fn minify(mut cx: FunctionContext) -> JsResult<JsBuffer> {
let src = cx.argument::<JsBuffer>(0)?;
let opt = cx.argument::<JsObject>(1)?;
let Ok(src) = cx.argument::<JsBuffer>(0) else {
return cx.throw_type_error("the first argument is not a Buffer");
};
let Ok(opt) = cx.argument::<JsObject>(1) else {
return cx.throw_type_error("the second argument is not an object");
};
let cfg = minify_html::Cfg {
do_not_minify_doctype: opt
.get_opt::<JsBoolean, _, _>(&mut cx, "do_not_minify_doctype")?
Expand Down

0 comments on commit 02ba438

Please sign in to comment.