Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 12, 2021
1 parent be31e88 commit d57620d
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/run/measure/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const spawnAndMeasure = async function ({
})

try {
return await handleErrorsAndMeasure({ ...args, onTaskExit })
return await handleStopAndMeasure({ ...args, onTaskExit })
} finally {
terminateRunnerProcess(childProcess)
}
Expand All @@ -86,30 +86,27 @@ const spawnAndMeasure = async function ({
// performed
// - This ensures that all initializers and finalizers are always called
// and in order
const handleErrorsAndMeasure = async function ({
stopState,
onTaskExit,
...args
}) {
const handleStopAndMeasure = async function (args) {
const returnValue = await Promise.race([
args.stopState.onAbort,
handleErrorsAndMeasure(args),
])
throwIfStopped(args.stopState)
return returnValue
}

const handleErrorsAndMeasure = async function ({ onTaskExit, ...args }) {
try {
const returnValue = await Promise.race([
stopState.onAbort,
onTaskExit,
runEvents({ ...args, stopState }),
])
throwIfStopped(stopState)
return returnValue
return await Promise.race([onTaskExit, runEvents(args)])
} catch (error) {
prependCombinationPrefix(error, args.combination)
throw error
}
}

// When an error happens while a measuring a specific combination, display its
// dimensions in the error message
const prependCombinationPrefix = function (error, combination) {
if (error.name === 'StopError') {
return
}

const combinationPrefix = getCombinationPrefix(combination)
error.message = `In ${combinationPrefix}:\n${error.message}`
}
Expand Down

0 comments on commit d57620d

Please sign in to comment.