-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
import { createErrorType } from './utils.js' | ||
|
||
// User aborting the benchmark | ||
export const StopError = createErrorType('StopError') | ||
// Bug in the library itself | ||
export const CoreError = createErrorType('CoreError') | ||
// Bug in a plugin (reporter|runner) | ||
export const PluginError = createErrorType('PluginError') | ||
// Invalid options | ||
export const UserError = createErrorType('UserError') | ||
// Invalid tasks or tasks file | ||
export const UserCodeError = createErrorType('UserCodeError') | ||
// Invalid options | ||
export const UserError = createErrorType('UserError') | ||
// `limit` option threshold was reached | ||
export const LimitError = createErrorType('LimitError') | ||
// User aborting the benchmark | ||
export const StopError = createErrorType('StopError') | ||
|
||
// Retrieve error type-specific behavior | ||
export const getErrorProps = function (error) { | ||
const { name } = error | ||
const nameA = | ||
typeof name === 'string' && name in ERROR_PROPS ? name : DEFAULT_ERROR_NAME | ||
return ERROR_PROPS[nameA] | ||
} | ||
// All error types, with first being default type | ||
export const ErrorTypes = [ | ||
CoreError, | ||
PluginError, | ||
UserCodeError, | ||
UserError, | ||
LimitError, | ||
StopError, | ||
] | ||
|
||
const ERROR_PROPS = { | ||
StopError: { exitCode: 0, printStack: false, indented: true }, | ||
CoreError: { exitCode: 1, printStack: true, indented: false }, | ||
PluginError: { exitCode: 2, printStack: true, indented: false }, | ||
UserError: { exitCode: 3, printStack: false, indented: false }, | ||
// Error type-specific behavior | ||
export const ERROR_PROPS = { | ||
CoreError: { exitCode: 5, printStack: true, indented: false }, | ||
PluginError: { exitCode: 4, printStack: true, indented: false }, | ||
UserCodeError: { exitCode: 3, printStack: true, indented: false }, | ||
LimitError: { exitCode: 4, printStack: false, indented: false }, | ||
UserError: { exitCode: 2, printStack: false, indented: false }, | ||
LimitError: { exitCode: 1, printStack: false, indented: false }, | ||
StopError: { exitCode: 0, printStack: false, indented: true }, | ||
} | ||
|
||
const DEFAULT_ERROR_NAME = 'CoreError' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,71 @@ | ||
import { listCombinations } from './combination/list.js' | ||
import { getConfig } from './config/main.js' | ||
import { performDev } from './dev/main.js' | ||
import { ErrorTypes } from './error/main.js' | ||
import { allowErrorTypes } from './error/types.js' | ||
import { checkLimits } from './history/compare/limit.js' | ||
import { getFromHistory, removeFromHistory } from './history/data/main.js' | ||
import { getTargetRawResults } from './history/merge/results.js' | ||
import { reportResult } from './report/main.js' | ||
import { createResult } from './run/create.js' | ||
import { performRun } from './run/main.js' | ||
// eslint-disable-next-line import/max-dependencies | ||
import { initPreview } from './run/preview/start_end/main.js' | ||
|
||
// Measure code defined in a tasks file and report the results. | ||
// Default command. | ||
export const run = async function (configFlags) { | ||
const config = await getConfig('run', configFlags) | ||
const previewState = initPreview(config) | ||
const { newResult, history } = await createResult(config) | ||
const programmaticResult = await performRun({ | ||
newResult, | ||
history, | ||
previewState, | ||
config, | ||
}) | ||
checkLimits(programmaticResult) | ||
return programmaticResult | ||
try { | ||
const config = await getConfig('run', configFlags) | ||
const previewState = initPreview(config) | ||
const { newResult, history } = await createResult(config) | ||
const programmaticResult = await performRun({ | ||
newResult, | ||
history, | ||
previewState, | ||
config, | ||
}) | ||
checkLimits(programmaticResult) | ||
return programmaticResult | ||
} catch (error) { | ||
throw allowErrorTypes(error, ErrorTypes) | ||
} | ||
} | ||
|
||
// Show a previous result | ||
export const show = async function (configFlags) { | ||
const config = await getConfig('show', configFlags) | ||
const { rawResult, history } = await getFromHistory(config) | ||
const programmaticResult = await reportResult(rawResult, history, config) | ||
checkLimits(programmaticResult) | ||
return programmaticResult | ||
try { | ||
const config = await getConfig('show', configFlags) | ||
const { rawResult, history } = await getFromHistory(config) | ||
const programmaticResult = await reportResult(rawResult, history, config) | ||
checkLimits(programmaticResult) | ||
return programmaticResult | ||
} catch (error) { | ||
throw allowErrorTypes(error, ErrorTypes) | ||
} | ||
} | ||
|
||
// Remove a previous result | ||
export const remove = async function (configFlags) { | ||
const config = await getConfig('remove', configFlags) | ||
const { rawResult, history } = await getFromHistory(config) | ||
const targetRawResults = getTargetRawResults(rawResult, history) | ||
const programmaticResult = await reportResult(rawResult, history, config) | ||
await removeFromHistory(targetRawResults, config) | ||
return programmaticResult | ||
try { | ||
const config = await getConfig('remove', configFlags) | ||
const { rawResult, history } = await getFromHistory(config) | ||
const targetRawResults = getTargetRawResults(rawResult, history) | ||
const programmaticResult = await reportResult(rawResult, history, config) | ||
await removeFromHistory(targetRawResults, config) | ||
return programmaticResult | ||
} catch (error) { | ||
throw allowErrorTypes(error, ErrorTypes) | ||
} | ||
} | ||
|
||
// Execute tasks without benchmarking them | ||
export const dev = async function (configFlags) { | ||
const config = await getConfig('dev', configFlags) | ||
const combinations = await listCombinations(config) | ||
await performDev(combinations, config) | ||
try { | ||
const config = await getConfig('dev', configFlags) | ||
const combinations = await listCombinations(config) | ||
await performDev(combinations, config) | ||
} catch (error) { | ||
throw allowErrorTypes(error, ErrorTypes) | ||
} | ||
} |