From 50dad7fa57158ea96945924f55809e6b1a0faa9f Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Tue, 4 Jul 2023 21:50:20 -0600 Subject: [PATCH] Work around napi-rs crash when cloning an error /~https://github.com/napi-rs/napi-rs/issues/1640 --- node/src/lib.rs | 2 +- node/test/bundle.test.mjs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/node/src/lib.rs b/node/src/lib.rs index 40b6584f..870b303f 100644 --- a/node/src/lib.rs +++ b/node/src/lib.rs @@ -372,7 +372,7 @@ mod bundle { 0, move |ctx: ThreadSafeCallContext| { if let Err(err) = ctx.value.stylesheet.visit(&mut visitor) { - ctx.value.tx.send(Err(err.clone())).expect("send error"); + ctx.value.tx.send(Err(err)).expect("send error"); return Ok(()); } ctx.value.tx.send(Ok(Default::default())).expect("send error"); diff --git a/node/test/bundle.test.mjs b/node/test/bundle.test.mjs index 03378249..d42979c1 100644 --- a/node/test/bundle.test.mjs +++ b/node/test/bundle.test.mjs @@ -373,4 +373,22 @@ test('should throw with location info on syntax errors', async () => { }); }); +test('should support throwing in visitors', async () => { + let error = undefined; + try { + await bundleAsync({ + filename: 'tests/testdata/a.css', + visitor: { + Rule() { + throw new Error('Some error') + } + } + }); + } catch (err) { + error = err; + } + + assert.equal(error.message, 'Some error'); +}); + test.run();