Skip to content

Commit

Permalink
Work around napi-rs crash when cloning an error
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Jul 5, 2023
1 parent bd517fd commit 50dad7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ mod bundle {
0,
move |ctx: ThreadSafeCallContext<VisitMessage>| {
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");
Expand Down
18 changes: 18 additions & 0 deletions node/test/bundle.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 50dad7f

Please sign in to comment.