if (this.emitter != null) {
this.emitter.emit(PoolEvents.taskError, message.taskError)
}
- promiseResponse.reject(
- `${message.taskError.message} on worker '${message.taskError.workerId}'`
- )
+ promiseResponse.reject(message.taskError.message)
} else {
promiseResponse.resolve(message.data as Response)
}
* @returns The error message.
*/
protected handleError (e: Error | string): string {
- return e as string
+ return e instanceof Error ? e.message : e
}
/**
id: message.id
})
} catch (e) {
- const err = this.handleError(e as Error)
+ const errorMessage = this.handleError(e as Error | string)
this.sendToMainWorker({
taskError: {
workerId: this.id,
- message: err,
+ message: errorMessage,
data: message.data
},
id: message.id
return null
})
.catch(e => {
- const err = this.handleError(e as Error)
+ const errorMessage = this.handleError(e as Error | string)
this.sendToMainWorker({
taskError: {
workerId: this.id,
- message: err,
+ message: errorMessage,
data: message.data
},
id: message.id
protected sendToMainWorker (message: MessageValue<Response>): void {
this.getMainWorker().send(message)
}
-
- /** @inheritDoc */
- protected handleError (e: Error | string): string {
- return e instanceof Error ? e.message : e
- }
}
protected sendToMainWorker (message: MessageValue<Response>): void {
this.getMainWorker().postMessage(message)
}
+
+ /** @inheritDoc */
+ protected handleError (e: Error | string): string {
+ return e as string
+ }
}
}
expect(inError).toBeDefined()
expect(typeof inError === 'string').toBe(true)
- expect(inError).toContain('Error Message from ClusterWorker on worker')
- expect(taskError.data).toStrictEqual(data)
+ expect(inError).toBe('Error Message from ClusterWorker')
+ expect(taskError).toStrictEqual({
+ workerId: expect.any(Number),
+ message: 'Error Message from ClusterWorker',
+ data
+ })
expect(
errorPool.workerNodes.some(
workerNode => workerNode.usage.tasks.failed === 1
}
expect(inError).toBeDefined()
expect(typeof inError === 'string').toBe(true)
- expect(inError).toContain(
- 'Error Message from ClusterWorker:async on worker'
- )
- expect(taskError.data).toStrictEqual(data)
+ expect(inError).toBe('Error Message from ClusterWorker:async')
+ expect(taskError).toStrictEqual({
+ workerId: expect.any(Number),
+ message: 'Error Message from ClusterWorker:async',
+ data
+ })
expect(
asyncErrorPool.workerNodes.some(
workerNode => workerNode.usage.tasks.failed === 1
expect(inError).toBeInstanceOf(Error)
expect(inError.message).toBeDefined()
expect(typeof inError.message === 'string').toBe(true)
- expect(inError.message).toContain(
- 'Error Message from ThreadWorker on worker'
- )
- expect(taskError.data).toStrictEqual(data)
+ expect(inError.message).toBe('Error Message from ThreadWorker')
+ expect(taskError).toStrictEqual({
+ workerId: expect.any(Number),
+ message: new Error('Error Message from ThreadWorker'),
+ data
+ })
expect(
errorPool.workerNodes.some(
workerNode => workerNode.usage.tasks.failed === 1
expect(inError).toBeInstanceOf(Error)
expect(inError.message).toBeDefined()
expect(typeof inError.message === 'string').toBe(true)
- expect(inError.message).toContain(
- 'Error Message from ThreadWorker:async on worker'
- )
- expect(taskError.data).toStrictEqual(data)
+ expect(inError.message).toBe('Error Message from ThreadWorker:async')
+ expect(taskError).toStrictEqual({
+ workerId: expect.any(Number),
+ message: new Error('Error Message from ThreadWorker:async'),
+ data
+ })
expect(
asyncErrorPool.workerNodes.some(
workerNode => workerNode.usage.tasks.failed === 1