From b0b55f57cb5e2bc363bc75d84b483c9c29a5d22f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 19 Sep 2023 14:09:43 +0200 Subject: [PATCH] refactor: improve error reporting at task functions handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 17 +++++++++++++---- tests/pools/abstract/abstract-pool.test.js | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 33585218..9aeeebed 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -782,9 +782,11 @@ export abstract class AbstractPool< ) { reject( new Error( - `Task function operation ${ + `Task function operation '${ message.taskFunctionOperation as string - } failed on worker ${message.workerId}` + }' failed on worker ${message.workerId} with error: '${ + message.workerError?.message as string + }'` ) ) } @@ -815,11 +817,18 @@ export abstract class AbstractPool< message => message.taskFunctionOperationStatus === false ) ) { + const errorResponse = responsesReceived.find( + response => response.taskFunctionOperationStatus === false + ) reject( new Error( - `Task function operation ${ + `Task function operation '${ message.taskFunctionOperation as string - } failed on worker ${message.workerId as number}` + }' failed on worker ${ + errorResponse?.workerId as number + } with error: '${ + errorResponse?.workerError?.message as string + }'` ) ) } diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 3f59396a..f6a54d5b 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -1420,6 +1420,27 @@ describe('Abstract pool test suite', () => { './tests/worker-files/thread/testMultipleTaskFunctionsWorker.js' ) await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1) + await expect( + dynamicThreadPool.setDefaultTaskFunction(0) + ).rejects.toThrowError( + new Error( + "Task function operation 'default' failed on worker 31 with error: 'TypeError: name parameter is not a string'" + ) + ) + await expect( + dynamicThreadPool.setDefaultTaskFunction(DEFAULT_TASK_NAME) + ).rejects.toThrowError( + new Error( + "Task function operation 'default' failed on worker 31 with error: 'Error: Cannot set the default task function reserved name as the default task function'" + ) + ) + await expect( + dynamicThreadPool.setDefaultTaskFunction('unknown') + ).rejects.toThrowError( + new Error( + "Task function operation 'default' failed on worker 31 with error: 'Error: Cannot set the default task function to a non-existing task function'" + ) + ) expect(dynamicThreadPool.listTaskFunctionNames()).toStrictEqual([ DEFAULT_TASK_NAME, 'jsonIntegerSerialization', -- 2.34.1