diff --git a/src/rpc-worker-loader.js b/src/rpc-worker-loader.js index ca9b766..6e8dd4d 100644 --- a/src/rpc-worker-loader.js +++ b/src/rpc-worker-loader.js @@ -16,6 +16,9 @@ function workerSetup() { .catch(e => { let error = { message: e }; if (e.stack) { + error = Object.assign({}, e); + + /* Include potentially nonenumerable values */ error.message = e.message; error.stack = e.stack; error.name = e.name; diff --git a/test/src/index.test.js b/test/src/index.test.js index 0b1bfc8..43f4951 100644 --- a/test/src/index.test.js +++ b/test/src/index.test.js @@ -26,6 +26,7 @@ describe('worker', () => { } catch (e) { expect(e).toEqual(Error('Error in worker.js')); + expect(e.foo).toEqual('bar'); } }); diff --git a/test/src/worker.js b/test/src/worker.js index 73b1049..9b1f960 100644 --- a/test/src/worker.js +++ b/test/src/worker.js @@ -7,7 +7,9 @@ export function foo() { } export function throwError() { - throw new Error('Error in worker.js'); + const toThrow = new Error('Error in worker.js'); + toThrow.foo = 'bar'; + throw toThrow; } export const bar = (a, b) => `${a} [bar:${otherBar}] ${b}`;