Skip to content

Commit 95b8870

Browse files
committed
Throw detailed error messages on failures
1 parent 1c3d824 commit 95b8870

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@ pub fn compress(buf: Box<[u8]>) -> Result<Box<[u8]>, JsValue> {
1515
set_panic_hook();
1616
let mut out = Vec::<u8>::new();
1717
let params = brotli::enc::BrotliEncoderParams::default();
18+
1819
match brotli::BrotliCompress(&mut buf.as_ref(), &mut out, &params) {
1920
Ok(_) => (),
20-
Err(_) => return Err(JsValue::from_str("brotli dec failed")),
21+
Err(e) => return Err(JsValue::from_str(&format!(
22+
"Brotli compress failed: {:?}", e
23+
))),
2124
}
25+
2226
Ok(out.into_boxed_slice())
2327
}
2428

2529
#[wasm_bindgen(js_name = decompress)]
2630
pub fn decompress(buf: Box<[u8]>) -> Result<Box<[u8]>, JsValue> {
2731
set_panic_hook();
2832
let mut out = Vec::<u8>::new();
33+
2934
match brotli::BrotliDecompress(&mut buf.as_ref(), &mut out) {
3035
Ok(_) => (),
31-
Err(_) => return Err(JsValue::from_str("brotli dec failed")),
36+
Err(e) => return Err(JsValue::from_str(&format!(
37+
"Brotli decompress failed: {:?}", e
38+
))),
3239
}
40+
3341
Ok(out.into_boxed_slice())
3442
}

0 commit comments

Comments
 (0)