diff --git a/src/runners/cli/handler/measure.js b/src/runners/cli/handler/measure.js index a0d5631d5..d91fdba5f 100644 --- a/src/runners/cli/handler/measure.js +++ b/src/runners/cli/handler/measure.js @@ -1,7 +1,6 @@ import { execa, execaCommand } from 'execa' import now from 'precise-now' -import { wrapError } from '../../../error/wrap.js' import { TasksRunError } from '../../common/error.js' // `beforeAll` and `afterAll` @@ -87,8 +86,8 @@ const spawnProcess = async function (command, { env, shell }) { return shell === 'none' ? await execaCommand(command, { ...EXECA_OPTIONS, env }) : await execa(command, { ...EXECA_OPTIONS, env, shell }) - } catch (error) { - throw wrapError(error, '', TasksRunError) + } catch (cause) { + throw new TasksRunError('', { cause }) } } diff --git a/src/runners/cli/handler/start/main.js b/src/runners/cli/handler/start/main.js index 99b6ffd90..12fdd5de9 100644 --- a/src/runners/cli/handler/start/main.js +++ b/src/runners/cli/handler/start/main.js @@ -1,4 +1,3 @@ -import { wrapError } from '../../../../error/wrap.js' import { loadYamlFile } from '../../../../utils/yaml.js' import { TasksLoadError } from '../../../common/error.js' @@ -27,8 +26,8 @@ export const start = async function ( const importFile = async function (taskPath) { try { return await loadYamlFile(taskPath) - } catch (error) { - throw wrapError(error, '', TasksLoadError) + } catch (cause) { + throw new TasksLoadError('', { cause }) } } diff --git a/src/runners/common/error.js b/src/runners/common/error.js index dc5cf918c..e0efe9b93 100644 --- a/src/runners/common/error.js +++ b/src/runners/common/error.js @@ -1,4 +1,5 @@ import { createErrorType } from '../../error/create.js' +import { mergeErrorCause } from '../../error/merge/main.js' import { allowErrorTypes } from '../../error/types.js' // Error from the library itself @@ -26,6 +27,7 @@ const ErrorTypes = [ // Serialize an error to send to parent export const serializeError = function (error) { - const { name, message, stack } = allowErrorTypes(error, ErrorTypes) + const errorA = mergeErrorCause(error) + const { name, message, stack } = allowErrorTypes(errorA, ErrorTypes) return { name, message, stack } } diff --git a/src/runners/common/ipc.js b/src/runners/common/ipc.js index 5475b2cf5..bd53345ca 100644 --- a/src/runners/common/ipc.js +++ b/src/runners/common/ipc.js @@ -2,8 +2,6 @@ import { argv } from 'process' import got from 'got' -import { wrapError } from '../../error/wrap.js' - import { serializeError, IpcSerializationError } from './error.js' // Handles IPC communication with the parent process @@ -48,8 +46,8 @@ const handlePayload = async function (payload, handlers, state) { const safeSerializeBody = function (returnValue = {}) { try { return serializeBody(returnValue) - } catch (error) { - throw wrapError(error, '', IpcSerializationError) + } catch (cause) { + throw new IpcSerializationError('', { cause }) } } diff --git a/src/runners/common/validate/file.js b/src/runners/common/validate/file.js index 994a0e937..d8a50ddd4 100644 --- a/src/runners/common/validate/file.js +++ b/src/runners/common/validate/file.js @@ -2,7 +2,6 @@ import { inspect } from 'util' import isPlainObj from 'is-plain-obj' -import { wrapError } from '../../../error/wrap.js' import { mapValues } from '../../../utils/map.js' import { TasksSyntaxError } from '../error.js' @@ -22,8 +21,8 @@ export const validateTasks = function ({ tasks, validators, normalizeTask }) { const validateTask = function ({ taskId, task, validators, normalizeTask }) { try { return eValidateTask({ task, validators, normalizeTask }) - } catch (error) { - throw wrapError(error, `Task "${taskId}"`) + } catch (cause) { + throw new Error(`Task "${taskId}":`, { cause }) } } diff --git a/src/runners/node/config/version.js b/src/runners/node/config/version.js index 16e20a0e6..7b5e6e19e 100644 --- a/src/runners/node/config/version.js +++ b/src/runners/node/config/version.js @@ -6,7 +6,6 @@ import { readPackageUp } from 'read-pkg-up' import semver from 'semver' import { normalizeNumberString } from '../../../config/normalize/transform.js' -import { wrapError } from '../../../error/wrap.js' // Normalize and validate the Node.js version const transformVersion = async function (version) { @@ -33,8 +32,8 @@ const normalizeVersion = async function (version) { try { return await nvexeca(versionA, 'node', { progress: true, dry: true }) - } catch (error) { - throw wrapError(error, 'must be a valid Node.js version:') + } catch (cause) { + throw new Error('must be a valid Node.js version:\n', { cause }) } } diff --git a/src/runners/node/handler/hooks.js b/src/runners/node/handler/hooks.js index 8d514a0e5..def86c670 100644 --- a/src/runners/node/handler/hooks.js +++ b/src/runners/node/handler/hooks.js @@ -1,4 +1,3 @@ -import { wrapError } from '../../../error/wrap.js' import { TasksRunError } from '../../common/error.js' // Perform `beforeAll`, if defined @@ -9,8 +8,8 @@ export const before = async function ({ task: { beforeAll }, inputs }) { try { await beforeAll(inputs) - } catch (error) { - throw wrapError(error, '', TasksRunError) + } catch (cause) { + throw new TasksRunError('', { cause }) } } @@ -22,7 +21,7 @@ export const after = async function ({ task: { afterAll }, inputs }) { try { await afterAll(inputs) - } catch (error) { - throw wrapError(error, '', TasksRunError) + } catch (cause) { + throw new TasksRunError('', { cause }) } } diff --git a/src/runners/node/handler/measure/main.js b/src/runners/node/handler/measure/main.js index 2898c8d44..fa68661b1 100644 --- a/src/runners/node/handler/measure/main.js +++ b/src/runners/node/handler/measure/main.js @@ -1,4 +1,3 @@ -import { wrapError } from '../../../../error/wrap.js' import { TasksRunError } from '../../../common/error.js' import { performLoopsAsync } from './async.js' @@ -32,7 +31,7 @@ export const measure = async function ( maxLoops, }) return { measures } - } catch (error) { - throw wrapError(error, '', TasksRunError) + } catch (cause) { + throw new TasksRunError('', { cause }) } } diff --git a/src/runners/node/handler/start/main.js b/src/runners/node/handler/start/main.js index 3cdcf35eb..0ae22b19d 100644 --- a/src/runners/node/handler/start/main.js +++ b/src/runners/node/handler/start/main.js @@ -1,4 +1,3 @@ -import { wrapError } from '../../../../error/wrap.js' import { importJsNamed } from '../../../../utils/import.js' import { TasksLoadError } from '../../../common/error.js' @@ -27,12 +26,10 @@ export const start = async function ( const importFile = async function (taskPath) { try { return await importJsNamed(taskPath) - } catch (error) { - throw wrapError( - error, - `Could not import the tasks file ${taskPath}\n`, - TasksLoadError, - ) + } catch (cause) { + throw new TasksLoadError(`Could not import the tasks file "${taskPath}"`, { + cause, + }) } } diff --git a/src/runners/node/handler/start/require_config.js b/src/runners/node/handler/start/require_config.js index d3a9f7cc9..96a319da6 100644 --- a/src/runners/node/handler/start/require_config.js +++ b/src/runners/node/handler/start/require_config.js @@ -1,6 +1,5 @@ import { pathToFileURL } from 'url' -import { wrapError } from '../../../../error/wrap.js' import { ConfigError } from '../../../common/error.js' // Use the `require` configuration property @@ -12,11 +11,10 @@ const useRequiredModule = async function (requiredModule) { try { // eslint-disable-next-line import/no-dynamic-require await import(pathToFileURL(requiredModule)) - } catch (error) { - throw wrapError( - error, - `Configuration property "runner.require" with value "${requiredModule}" could not be imported.\n`, - ConfigError, + } catch (cause) { + throw new ConfigError( + `Configuration property "runner.require" with value "${requiredModule}" could not be imported.`, + { cause }, ) } }