Skip to content

Commit

Permalink
fix(#513): forward errors correctly to Piscina (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 authored Feb 16, 2024
1 parent a7042ea commit 6945d21
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function onMessage (
result: null,
// It may be worth taking a look at the error cloning algorithm we
// use in Node.js core here, it's quite a bit more flexible
error: error instanceof Error ? error : null
error: <Error>error
};
}
currentTasks--;
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/vm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// worker.js
const vm = require('vm');

module.exports = ({ payload, context }) => {
const script = new vm.Script(payload);
script.runInNewContext(context);
};
19 changes: 19 additions & 0 deletions test/issue-513.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Piscina from '..';
import { test } from 'tap';
import { resolve } from 'path';

test('pool will maintain run and wait time histograms', async ({
equal,
fail
}) => {
const pool = new Piscina({
filename: resolve(__dirname, 'fixtures/vm.js')
});

try {
await pool.run({ payload: 'throw new Error("foo")' });
fail('Expected an error');
} catch (error) {
equal(error.message, 'foo');
}
});

0 comments on commit 6945d21

Please sign in to comment.