diff --git a/package-lock.json b/package-lock.json index 3cd082ae0..9ec1af69f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "mocha": "^10.2.0", "plugins-loader": "^1.1.0", "png-validator": "1.1.0", + "serialize-error": "^8.1.0", "sharp": "~0.30.7", "sizzle": "^2.3.6", "temp": "^0.8.3", diff --git a/package.json b/package.json index 2d740746c..d3c965c6b 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "mocha": "^10.2.0", "plugins-loader": "^1.1.0", "png-validator": "1.1.0", + "serialize-error": "^8.1.0", "sharp": "~0.30.7", "sizzle": "^2.3.6", "temp": "^0.8.3", diff --git a/src/utils/processor.js b/src/utils/processor.js index 64ab28fbc..0f6d76e2b 100644 --- a/src/utils/processor.js +++ b/src/utils/processor.js @@ -1,5 +1,6 @@ "use strict"; +const { serializeError, deserializeError } = require("serialize-error"); const { WORKER_UNHANDLED_REJECTION } = require("../constants/process-messages"); const ipc = require("./ipc"); @@ -15,7 +16,16 @@ module.exports = async (module, methodName, args, cb) => { try { const result = await require(module)[methodName](...args); cb(null, result); - } catch (e) { - cb(e); + } catch (err) { + sendError(err, cb); } }; + +function sendError(err, cb) { + try { + cb(err); + } catch { + const errWithoutCircularRefs = deserializeError(serializeError(err)); + cb(errWithoutCircularRefs); + } +}