From ef0ab0165209ff01918c4806d4106e5efd9a7304 Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Sun, 10 Dec 2023 23:33:05 +0000 Subject: [PATCH] fix(ignite): register only one uncaught ehandler --- package-lock.json | 4 ++-- package.json | 2 +- src/ignite/Ignite.ts | 11 +++++++---- tests/unit/ignite/IgniteTest.ts | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8714e66..f882ca1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/core", - "version": "4.14.0", + "version": "4.14.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/core", - "version": "4.14.0", + "version": "4.14.1", "license": "MIT", "dependencies": { "pretty-repl": "^3.1.2", diff --git a/package.json b/package.json index 7890aff..af819da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/core", - "version": "4.14.0", + "version": "4.14.1", "description": "The plug and play Node.js framework.", "license": "MIT", "author": "João Lenon ", diff --git a/src/ignite/Ignite.ts b/src/ignite/Ignite.ts index aa698d3..9b73e0f 100644 --- a/src/ignite/Ignite.ts +++ b/src/ignite/Ignite.ts @@ -193,11 +193,14 @@ export class Ignite { * ``` */ public setUncaughtExceptionHandler(): void { + /** + * Remove listeners registered more then once by + * Ignite class. + */ if (process.listeners('uncaughtException').length) { - process.removeListener( - 'uncaughtException', - this.options.uncaughtExceptionHandler - ) + process.listeners('uncaughtException').forEach(l => { + process.removeListener('uncaughtException', l) + }) } process.on('uncaughtException', this.options.uncaughtExceptionHandler) diff --git a/tests/unit/ignite/IgniteTest.ts b/tests/unit/ignite/IgniteTest.ts index 47bbbb4..c8d0fc2 100644 --- a/tests/unit/ignite/IgniteTest.ts +++ b/tests/unit/ignite/IgniteTest.ts @@ -132,7 +132,7 @@ export default class IgniteTest { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - assert.lengthOf(process?._events?.uncaughtException, 3) + assert.lengthOf(process?._events?.uncaughtException, 2) } @Test()