From f8d222ad76226e43639229985cf6c563609774d2 Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Tue, 28 Nov 2023 03:05:24 +0300 Subject: [PATCH] feat: add basic unhandled rejection stack trace --- src/cli/index.js | 9 ++++++--- src/utils/processor.js | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cli/index.js b/src/cli/index.js index be15e3b79..2d3c20d70 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -1,5 +1,6 @@ "use strict"; +const _ = require("lodash"); const { Command } = require("@gemini-testing/commander"); const escapeRe = require("escape-string-regexp"); @@ -23,9 +24,11 @@ process.on("unhandledRejection", (reason, p) => { return; } - const error = `Unhandled Rejection in hermione:master:${process.pid}:\nPromise: ${JSON.stringify( - p, - )}\nReason: ${reason}`; + const error = [ + `Unhandled Rejection in hermione:master:${process.pid}:`, + `Promise: ${JSON.stringify(p)}`, + `Reason: ${_.get(reason, "stack", reason)}`, + ].join("\n"); if (hermione) { hermione.halt(error); diff --git a/src/utils/processor.js b/src/utils/processor.js index 3594eb00b..28c36fa1d 100644 --- a/src/utils/processor.js +++ b/src/utils/processor.js @@ -11,9 +11,11 @@ process.on("unhandledRejection", (reason, p) => { return; } - const error = `Unhandled Rejection in hermione:worker:${process.pid}:\nPromise: ${JSON.stringify( - p, - )}\nReason: ${reason}`; + const error = [ + `Unhandled Rejection in hermione:worker:${process.pid}:`, + `Promise: ${JSON.stringify(p)}`, + `Reason: ${_.get(reason, "stack", reason)}`, + ].join("\n"); ipc.emit(WORKER_UNHANDLED_REJECTION, { error }); });