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();