/**
* Task function name triggering the error.
*/
- readonly name: string
+ readonly name?: string
+ /**
+ * Error stack trace.
+ */
+ readonly stack?: string
}
/**
data,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
message: `Task function '${name!}' not found`,
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- name: name!,
+ name,
},
})
return
taskId,
workerError: {
data,
- message: this.handleError(error as Error | string),
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- name: name!,
+ message: this.handleErrorMessage(error as Error | string),
+ name,
+ stack: (error as Error).stack,
},
})
})
taskId,
workerError: {
data,
- message: this.handleError(error as Error | string),
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- name: name!,
+ message: this.handleErrorMessage(error as Error | string),
+ name,
+ stack: (error as Error).stack,
},
})
} finally {
}
/**
- * Handles an error and convert it to a string so it can be sent back to the main worker.
+ * Handles an error and convert it if needed to its message string.
+ * Error are not structured-cloneable and cannot be sent to the main worker.
* @param error - The error raised by the worker.
* @returns The error message.
*/
- protected handleError (error: Error | string): string {
+ protected handleErrorMessage (error: Error | string): string {
return error instanceof Error ? error.message : error
}
...(!status &&
error != null && {
workerError: {
- message: this.handleError(error as Error | string),
+ message: this.handleErrorMessage(error as Error | string),
name: taskFunctionProperties.name,
+ stack: error.stack,
},
}),
})
/**
* @inheritDoc
*/
- protected override handleError (error: Error | string): string {
+ protected override handleErrorMessage (error: Error | string): string {
return error as string
}
data,
message: 'Error Message from ClusterWorker',
name: DEFAULT_TASK_NAME,
+ stack: expect.any(String),
})
expect(
errorPool.workerNodes.some(
data,
message: 'Error Message from ClusterWorker:async',
name: DEFAULT_TASK_NAME,
+ stack: expect.any(String),
})
expect(
asyncErrorPool.workerNodes.some(
data,
message: new Error('Error Message from ThreadWorker'),
name: DEFAULT_TASK_NAME,
+ stack: expect.any(String),
})
expect(
errorPool.workerNodes.some(
data,
message: new Error('Error Message from ThreadWorker:async'),
name: DEFAULT_TASK_NAME,
+ stack: expect.any(String),
})
expect(
asyncErrorPool.workerNodes.some(
expect(worker.getMainWorker().send.calledOnce).toBe(true)
})
- it('Verify that handleError() method is working properly', () => {
+ it('Verify that handleErrorMessage() method is working properly', () => {
const error = new Error('Error as an error')
const worker = new ClusterWorker(() => {})
- expect(worker.handleError(error)).toStrictEqual(error.message)
+ expect(worker.handleErrorMessage(error)).toStrictEqual(error.message)
const errorMessage = 'Error as a string'
- expect(worker.handleError(errorMessage)).toStrictEqual(errorMessage)
+ expect(worker.handleErrorMessage(errorMessage)).toStrictEqual(errorMessage)
})
it('Verify that sendToMainWorker() method invokes the getMainWorker() and send() methods', () => {
expect(worker.port.postMessage.calledOnce).toBe(true)
})
- it('Verify that handleError() method is working properly', () => {
+ it('Verify that handleErrorMessage() method is working properly', () => {
const error = new Error('Error as an error')
const worker = new ThreadWorker(() => {})
- expect(worker.handleError(error)).toStrictEqual(error)
+ expect(worker.handleErrorMessage(error)).toStrictEqual(error)
const errorMessage = 'Error as a string'
- expect(worker.handleError(errorMessage)).toStrictEqual(errorMessage)
+ expect(worker.handleErrorMessage(errorMessage)).toStrictEqual(errorMessage)
})
it('Verify that sendToMainWorker() method invokes the port property postMessage() method', () => {