From: Jérôme Benoit Date: Tue, 19 Sep 2023 12:09:43 +0000 (+0200) Subject: refactor: improve error reporting at task functions handling X-Git-Tag: v2.7.0~1^2~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;ds=inline;h=b0b55f57cb5e2bc363bc75d84b483c9c29a5d22f;hp=d28c70ad5ebe6f2470352954454c94c7bd8459fa;p=poolifier.git refactor: improve error reporting at task functions handling Signed-off-by: Jérôme Benoit --- 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',