WorkerError.js 893 B

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