From f7fa6265238388a83fd562e7f3ce49475e79e2dc Mon Sep 17 00:00:00 2001 From: shadowusr <58862284+shadowusr@users.noreply.github.com> Date: Wed, 24 Jan 2024 17:04:20 +0300 Subject: [PATCH] fix: ignore objectId puppeteer error (#832) --- src/cli/index.js | 3 ++- src/utils/errors.ts | 15 +++++++++++++++ src/utils/processor.js | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/utils/errors.ts diff --git a/src/cli/index.js b/src/cli/index.js index 3d44fc367..71af0e804 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -10,6 +10,7 @@ const { Hermione } = require("../hermione"); const pkg = require("../../package.json"); const logger = require("../utils/logger"); const { requireModule } = require("../utils/module"); +const { shouldIgnoreUnhandledRejection } = require("../utils/errors"); let hermione; @@ -19,7 +20,7 @@ process.on("uncaughtException", err => { }); process.on("unhandledRejection", (reason, p) => { - if (reason && reason.name === "ProtocolError") { + if (shouldIgnoreUnhandledRejection(reason)) { logger.warn(`Unhandled Rejection "${reason}" in hermione:master:${process.pid} was ignored`); return; } diff --git a/src/utils/errors.ts b/src/utils/errors.ts new file mode 100644 index 000000000..03120e0e4 --- /dev/null +++ b/src/utils/errors.ts @@ -0,0 +1,15 @@ +export const shouldIgnoreUnhandledRejection = (err: Error | undefined): boolean => { + if (!err) { + return false; + } + + if (err.name === "ProtocolError") { + return true; + } + + if (/Cannot extract value when objectId is given/.test(err.message) && err.stack?.includes("/puppeteer-core/")) { + return true; + } + + return false; +}; diff --git a/src/utils/processor.js b/src/utils/processor.js index 28c36fa1d..637cab906 100644 --- a/src/utils/processor.js +++ b/src/utils/processor.js @@ -4,9 +4,10 @@ const _ = require("lodash"); const { WORKER_UNHANDLED_REJECTION } = require("../constants/process-messages"); const logger = require("./logger"); const ipc = require("./ipc"); +const { shouldIgnoreUnhandledRejection } = require("./errors"); process.on("unhandledRejection", (reason, p) => { - if (reason && reason.name === "ProtocolError") { + if (shouldIgnoreUnhandledRejection(reason)) { logger.warn(`Unhandled Rejection "${reason}" in hermione:worker:${process.pid} was ignored`); return; }