Skip to content

Commit

Permalink
Improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 12, 2021
1 parent ff42e21 commit be31e88
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/combination/list/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ export const listCombinations = async function ({
}

// Get cartesian product of all combinations
// `taskPath` is not set in `dimensions.task.path` because it used by the `init`
// stage before task dimension ids are known.
const getCombinationsProduct = function ({ tasks, inputs, systemId }) {
if (tasks.length === 0) {
throw new UserError(`Please specify some "tasks".`)
}

return tasks.map(({ id, path, runner }) => ({
dimensions: { task: { id, path }, runner, system: { id: systemId } },
return tasks.map(({ id, taskPath, runner }) => ({
dimensions: { task: { id }, runner, system: { id: systemId } },
taskPath,
inputs,
stats: {},
}))
Expand Down
16 changes: 8 additions & 8 deletions src/combination/tasks/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ import { measureCombinations } from '../../run/measure/main.js'
// to several tasks competing for optimization in the same process
// So we spawn a single process for all of them, to retrieve the task and step
// identifiers.
export const findTasks = async function (path, cwd, runner) {
await validateTask(path)
export const findTasks = async function (taskPath, cwd, runner) {
await validateTask(taskPath)

try {
const [{ taskIds: ids }] = await measureCombinations(
[{ dimensions: { task: { path }, runner }, inputs: [] }],
[{ dimensions: { runner }, taskPath, inputs: [] }],
{ precisionTarget: 0, cwd, previewState: { quiet: true }, stage: 'init' },
)
validateDuplicateTaskIds(ids)
return ids.map((id) => ({ id, path, runner }))
return ids.map((id) => ({ id, taskPath, runner }))
} catch (error) {
error.message = `In tasks file "${path}" (runner "${runner.id}")\n${error.message}`
error.message = `In tasks file "${taskPath}":\n${error.message}`
throw error
}
}

const validateTask = async function (path) {
if (!(await isFile(path))) {
throw new UserError(`Tasks file does not exist: ${path}`)
const validateTask = async function (taskPath) {
if (!(await isFile(taskPath))) {
throw new UserError(`Tasks file does not exist: ${taskPath}`)
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/run/measure/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ export const runEvents = async function ({ combination, ...args }) {
}

// Start combination, i.e. make it load the combination and run any
// runner-defined start logic
// runner-defined start logic.
// `task.id` is `undefined` during `init` stage.
const startCombination = async function (
{
dimensions: {
task: { id, path },
task: { id } = {},
runner: { config },
},
taskPath,
inputs,
},
server,
Expand All @@ -36,7 +38,7 @@ const startCombination = async function (
event: 'start',
runnerConfig: config,
taskId: id,
taskPath: path,
taskPath,
inputs: inputsObj,
},
server,
Expand Down
8 changes: 4 additions & 4 deletions src/run/measure/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ const handleErrorsAndMeasure = async function ({
throwIfStopped(stopState)
return returnValue
} catch (error) {
prependCombinationPrefix(error, args.combination, args.stage)
prependCombinationPrefix(error, args.combination)
throw error
}
}

const prependCombinationPrefix = function (error, combination, stage) {
if (stage === 'init' || error.name === 'StopError') {
const prependCombinationPrefix = function (error, combination) {
if (error.name === 'StopError') {
return
}

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

const getCombinationPrefix = function (combination) {
Expand Down

0 comments on commit be31e88

Please sign in to comment.