WorkerError.js 846 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. const stack = (err, worker, workerId) => {
  6. const originError = (err.stack || '').split('\n').filter(line => line.trim().startsWith('at'));
  7. const workerError = worker.split('\n').filter(line => line.trim().startsWith('at'));
  8. const diff = workerError.slice(0, workerError.length - originError.length).join('\n');
  9. originError.unshift(diff);
  10. originError.unshift(err.message);
  11. originError.unshift(`Thread Loader (Worker ${workerId})`);
  12. return originError.join('\n');
  13. };
  14. class WorkerError extends Error {
  15. constructor(err, workerId) {
  16. super(err);
  17. this.name = err.name;
  18. this.message = err.message;
  19. Error.captureStackTrace(this, this.constructor);
  20. this.stack = stack(err, this.stack, workerId);
  21. }
  22. }
  23. exports.default = WorkerError;