PromiseResponseWrapper,
Task,
TaskFunctionProperties,
+ WorkerError,
} from '../utility-types.js'
import type {
TaskFunction,
const { asyncResource, reject, resolve, workerNodeKey } = promiseResponse
const workerNode = this.workerNodes[workerNodeKey]
if (workerError != null) {
- let error: Error
- if (workerError.error != null) {
- error = workerError.error
- } else {
- const err = new Error(workerError.message)
- err.stack = workerError.stack
- error = err
- }
this.emitter?.emit(PoolEvents.taskError, workerError)
+ const error = this.handleWorkerError(workerError)
asyncResource != null
? asyncResource.runInAsyncScope(reject, this.emitter, error)
: reject(error)
}
}
+ private handleWorkerError (workerError: WorkerError): Error {
+ if (workerError.error != null) {
+ return workerError.error
+ }
+ const error = new Error(workerError.message)
+ error.stack = workerError.stack
+ return error
+ }
+
private handleWorkerReadyResponse (message: MessageValue<Response>): void {
const { ready, taskFunctionsProperties, workerId } = message
if (ready == null || !ready) {