Skip to content

Commit

Permalink
Rename AnyError to BaseError
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Nov 13, 2022
1 parent 6293992 commit 336a31a
Show file tree
Hide file tree
Showing 26 changed files with 76 additions and 76 deletions.
4 changes: 2 additions & 2 deletions src/bin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url'
import { readPackageUp } from 'read-pkg-up'
import UpdateNotifier from 'update-notifier'

import { AnyError } from '../error/main.js'
import { BaseError } from '../error/main.js'
import { run, show, remove, dev } from '../main.js'

import { parseCliFlags } from './parse.js'
Expand Down Expand Up @@ -38,7 +38,7 @@ const runCli = async function () {
const { command, configFlags } = parseCliFlags(yargs)
await COMMANDS[command](configFlags)
} catch (error) {
AnyError.normalize(error).exit()
BaseError.normalize(error).exit()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/combination/tasks/find.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnyError, PluginError } from '../../error/main.js'
import { BaseError, PluginError } from '../../error/main.js'
import { measureCombinations } from '../../run/measure/main.js'

// Each combination has its own process, in order to prevent them from
Expand Down Expand Up @@ -27,7 +27,7 @@ export const findTasks = async function ({
validateDuplicateTaskIds(ids)
return ids.map((id) => ({ id, taskPath, runner }))
} catch (cause) {
throw new AnyError(`Tasks file: "${taskPath}"`, { cause })
throw new BaseError(`Tasks file: "${taskPath}"`, { cause })
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/combination/tasks/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { handlePluginError } from '../../config/plugin/error.js'
import { AnyError, PluginError } from '../../error/main.js'
import { BaseError, PluginError } from '../../error/main.js'
import { getCommonVersions } from '../../top/system/versions/common.js'
import { getCombsNoDimensions } from '../filter.js'

Expand Down Expand Up @@ -115,7 +115,7 @@ const getDimensionsTasks = async function ({
)
return tasks.flat()
} catch (error) {
throw handlePluginError({ error, bugs, PluginError, AnyError })
throw handlePluginError({ error, bugs, PluginError, BaseError })
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/config/load/resolve.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createRequire } from 'node:module'

import { AnyError } from '../../error/main.js'
import { BaseError } from '../../error/main.js'

// The `config` can be:
// - a Node module name starting with "[@scope/]spyd-config-"
Expand All @@ -19,7 +19,7 @@ const resolveNpm = function (configOpt, cwd) {
try {
return createRequire(`${cwd}/`).resolve(configOpt)
} catch (error) {
throw new AnyError(
throw new BaseError(
`must be a valid package name.
This Node module was not found, please ensure it is installed:\n`,
{ cause: error },
Expand Down
8 changes: 4 additions & 4 deletions src/config/normalize/lib/call/prefix.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AnyError } from '../error.js'
import { BaseError } from '../error.js'

// The `prefix` is the name of the type of property to show in error
// message and warnings such as "Option".
export const addInputPrefix = function (error, prefix, originalName) {
return new AnyError(`${prefix} "${originalName}":`, { cause: error })
return new BaseError(`${prefix} "${originalName}":`, { cause: error })
}

export const addDefinitionPrefix = function ({
Expand All @@ -14,7 +14,7 @@ export const addDefinitionPrefix = function ({
isValidation,
}) {
const suffix = isValidation ? 'definition:' : 'must have a valid definition.'
return new AnyError(
return new BaseError(
`${prefix} "${originalName}"'s keyword "${keyword}" ${suffix}`,
{ cause: error },
)
Expand All @@ -26,7 +26,7 @@ export const addKeywordPrefix = function ({
originalName,
keyword,
}) {
return new AnyError(
return new BaseError(
`${prefix} "${originalName}"'s keyword "${keyword}" bug.`,
{ cause: error },
)
Expand Down
4 changes: 2 additions & 2 deletions src/config/normalize/lib/call/suffix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inspect } from 'node:util'

import { AnyError } from '../error.js'
import { BaseError } from '../error.js'

// Add the current definition as error suffix
export const addCurrentDefinition = function (error, definition) {
Expand Down Expand Up @@ -29,7 +29,7 @@ export const addExampleInput = function ({ error, example, hasInput, test }) {
}

const addSuffix = function (error, name, value) {
return new AnyError(`${name}:${serializeValue(value)}`, { cause: error })
return new BaseError(`${name}:${serializeValue(value)}`, { cause: error })
}

const serializeValue = function (value) {
Expand Down
10 changes: 5 additions & 5 deletions src/config/normalize/lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import modernErrorsBugs from 'modern-errors-bugs'

import { bugs } from '../../../utils/package.js'

export const AnyError = modernErrors([modernErrorsBugs])
export const BaseError = modernErrors([modernErrorsBugs])

/* jscpd:ignore-start */
export const UnknownError = AnyError.subclass('UnknownError', { bugs })
export const UnknownError = BaseError.subclass('UnknownError', { bugs })
/* jscpd:ignore-end */

// Invalid `inputs`
export const InputError = AnyError.subclass('InputError')
export const InputError = BaseError.subclass('InputError')

// Invalid `rules` or `options`
export const DefinitionError = AnyError.subclass('DefinitionError')
export const DefinitionError = BaseError.subclass('DefinitionError')

// Bug in a keyword|plugin
export const KeywordError = AnyError.subclass('KeywordError')
export const KeywordError = BaseError.subclass('KeywordError')
4 changes: 2 additions & 2 deletions src/config/normalize/lib/keywords/normalize/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { inspect } from 'node:util'

import isPlainObj from 'is-plain-obj'

import { AnyError, DefinitionError } from '../../error.js'
import { BaseError, DefinitionError } from '../../error.js'

import { validateName } from './name.js'
import { validateKeywordProps } from './props.js'
Expand All @@ -24,6 +24,6 @@ const validateKeyword = function (keyword, index, keywords) {
try {
validateKeywordProps(keyword, index, keywords)
} catch (cause) {
throw new AnyError(`Invalid keyword "${keyword.name}":`, { cause })
throw new BaseError(`Invalid keyword "${keyword.name}":`, { cause })
}
}
4 changes: 2 additions & 2 deletions src/config/normalize/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { list } from 'wild-wild-path'

import { cleanObject } from '../../../utils/clean.js'

import { AnyError, InputError } from './error.js'
import { BaseError, InputError } from './error.js'
import { getInfo } from './info.js'
import { applyKeywords } from './keywords/main.js'
import { normalizeOpts } from './options.js'
Expand Down Expand Up @@ -115,7 +115,7 @@ const LIST_OPTS = { childFirst: true, sort: true, missing: true, entries: true }
// When in `sort` mode, input errors are returned instead of being thrown.
// Other errors are always propagated.
const handleError = function (error, soft) {
const errorA = AnyError.normalize(error)
const errorA = BaseError.normalize(error)

if (soft && errorA instanceof InputError) {
return { error: errorA, warnings: [] }
Expand Down
4 changes: 2 additions & 2 deletions src/config/plugin/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ export const handlePluginError = function ({
error,
bugs,
PluginError,
AnyError,
BaseError,
}) {
return error instanceof PluginError && typeof bugs === 'string'
? new AnyError('', { cause: error, bugs })
? new BaseError('', { cause: error, bugs })
: error
}
10 changes: 5 additions & 5 deletions src/config/plugin/lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import modernErrorsBugs from 'modern-errors-bugs'

import { bugs } from '../../../utils/package.js'

export const AnyError = modernErrors([modernErrorsBugs])
export const BaseError = modernErrors([modernErrorsBugs])

export const UnknownError = AnyError.subclass('UnknownError', { bugs })
export const UnknownError = BaseError.subclass('UnknownError', { bugs })

// Error from the library's user, who defines available plugin types
export const UserError = AnyError.subclass('UserError')
export const UserError = BaseError.subclass('UserError')

// Error from a plugin author, who defines a specific plugin
export const PluginError = AnyError.subclass('PluginError')
export const PluginError = BaseError.subclass('PluginError')

// Error from a plugin user
export const ConsumerError = AnyError.subclass('ConsumerError')
export const ConsumerError = BaseError.subclass('ConsumerError')
6 changes: 3 additions & 3 deletions src/config/plugin/lib/info.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { handlePluginError } from '../error.js'

import { normalizePluginConfig } from './config.js'
import { AnyError, PluginError } from './error.js'
import { BaseError, PluginError } from './error.js'
import { importPlugin } from './import.js'
import { normalizeLocation } from './location_normalize.js'
import { getLocationType } from './location_type.js'
Expand Down Expand Up @@ -64,12 +64,12 @@ const normalizePluginInfo = async function ({
})
return { plugin: pluginB, config: pluginConfigA }
} catch (error) {
throw handlePluginError({ error, bugs, PluginError, AnyError })
throw handlePluginError({ error, bugs, PluginError, BaseError })
}
}

const addPluginErrorLocation = function (error, originalLocation) {
return error instanceof PluginError
? new AnyError(`Invalid plugin "${originalLocation}".`, { cause: error })
? new BaseError(`Invalid plugin "${originalLocation}".`, { cause: error })
: error
}
6 changes: 3 additions & 3 deletions src/config/plugin/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { handlePluginError } from '../error.js'

import { validateDuplicatePlugins } from './duplicates.js'
import { AnyError, UserError } from './error.js'
import { BaseError, UserError } from './error.js'
import { getPluginInfo } from './info.js'
import { normalizeMultipleOpts, normalizeSingleOpts } from './options.js'

Expand Down Expand Up @@ -69,9 +69,9 @@ const validateDefined = function (value, { name }) {

const handleError = function (error, { bugs }) {
return handlePluginError({
error: AnyError.normalize(error),
error: BaseError.normalize(error),
bugs,
PluginError: UserError,
AnyError,
BaseError,
})
}
4 changes: 2 additions & 2 deletions src/config/plugin/lib/module.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createRequire } from 'node:module'

import { AnyError } from './error.js'
import { BaseError } from './error.js'

// Resolve Node module names to absolute file paths.
// We enforce a npm package naming convention for all plugins.
Expand All @@ -14,7 +14,7 @@ export const resolveModuleLocation = function (
try {
return createRequire(`${cwd}/`).resolve(moduleName)
} catch (cause) {
throw new AnyError(
throw new BaseError(
`must be ${getBuiltinsError(builtins)}
This Node module was not found, please ensure it is installed:\n`,
{ cause },
Expand Down
14 changes: 7 additions & 7 deletions src/error/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@ import modernErrorsCli from 'modern-errors-cli'

import { bugs } from '../utils/package.js'

export const AnyError = modernErrors([
export const BaseError = modernErrors([
modernErrorsBugs,
modernErrorsCli,
modernErrorsClean,
])

export const UnknownError = AnyError.subclass('UnknownError', {
export const UnknownError = BaseError.subclass('UnknownError', {
bugs,
cli: { exitCode: 1, header: 'red bold', icon: 'cross' },
})

// Bug in a plugin (reporter|runner)
export const PluginError = AnyError.subclass('PluginError', {
export const PluginError = BaseError.subclass('PluginError', {
cli: { exitCode: 2, header: 'magenta bold', icon: 'star' },
})

// Tasks failed to load or run
export const TaskError = AnyError.subclass('TaskError', {
export const TaskError = BaseError.subclass('TaskError', {
cli: { exitCode: 3, header: 'yellow bold', icon: 'pointer' },
})

// Invalid syntax with options or tasks file
export const UserError = AnyError.subclass('UserError', {
export const UserError = BaseError.subclass('UserError', {
cli: { exitCode: 4, header: 'yellow bold', icon: 'warning', stack: false },
})

// `limit` option threshold was reached
export const LimitError = AnyError.subclass('LimitError', {
export const LimitError = BaseError.subclass('LimitError', {
cli: { exitCode: 5, header: 'cyan bold', icon: 'triangleDown', stack: false },
})

// User aborting the benchmark
export const StopError = AnyError.subclass('StopError', {
export const StopError = BaseError.subclass('StopError', {
cli: { exitCode: 6, header: 'gray bold', icon: 'hamburger', stack: false },
})
4 changes: 2 additions & 2 deletions src/history/delta/transform.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnyError } from '../../error/main.js'
import { BaseError } from '../../error/main.js'
import { findValue } from '../../utils/find.js'

import { getDeltaTypeMessage } from './error.js'
Expand Down Expand Up @@ -31,7 +31,7 @@ const parseDelta = function ({ parse, type }, deltaOriginal) {
const value = parse(deltaOriginal)
return value === undefined ? undefined : { type, value }
} catch (cause) {
throw new AnyError(`must be a valid ${getDeltaTypeMessage(type)}.`, {
throw new BaseError(`must be a valid ${getDeltaTypeMessage(type)}.`, {
cause,
})
}
Expand Down
10 changes: 5 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { listCombinations } from './combination/list.js'
import { getConfig } from './config/main.js'
import { performDev } from './dev/main.js'
import { AnyError } from './error/main.js'
import { BaseError } from './error/main.js'
import { checkLimits } from './history/compare/limit.js'
import { getFromHistory, removeFromHistory } from './history/data/main.js'
import { getTargetRawResults } from './history/merge/results.js'
Expand All @@ -27,7 +27,7 @@ export const run = async function (configFlags) {
checkLimits(programmaticResult)
return programmaticResult
} catch (error) {
throw AnyError.normalize(error)
throw BaseError.normalize(error)
}
}

Expand All @@ -40,7 +40,7 @@ export const show = async function (configFlags) {
checkLimits(programmaticResult)
return programmaticResult
} catch (error) {
throw AnyError.normalize(error)
throw BaseError.normalize(error)
}
}

Expand All @@ -54,7 +54,7 @@ export const remove = async function (configFlags) {
await removeFromHistory(targetRawResults, config)
return programmaticResult
} catch (error) {
throw AnyError.normalize(error)
throw BaseError.normalize(error)
}
}

Expand All @@ -65,6 +65,6 @@ export const dev = async function (configFlags) {
const combinations = await listCombinations(config)
await performDev(combinations, config)
} catch (error) {
throw AnyError.normalize(error)
throw BaseError.normalize(error)
}
}
4 changes: 2 additions & 2 deletions src/report/error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { handlePluginError } from '../config/plugin/error.js'
import { PluginError, AnyError } from '../error/main.js'
import { PluginError, BaseError } from '../error/main.js'

// Create a reporter plugin error
export const getReporterPluginError = function (reporter, ...args) {
Expand All @@ -8,6 +8,6 @@ export const getReporterPluginError = function (reporter, ...args) {
error,
bugs: reporter.bugs,
PluginError,
AnyError,
BaseError,
})
}
Loading

0 comments on commit 336a31a

Please sign in to comment.