lib/errors

Contains error codes, factory functions to create throwable error objects,
and warning/deprecation functions.

Source:

Namespaces

constants

Methods

(static) createFatalError(message) → {Error}

Source:

Creates an error object to be thrown when an unrecoverable error occurs.

Parameters:
NameTypeDescription
messagestring

Error message to be displayed.

Returns:

instance detailing the error condition

Type
Error

(static) createForbiddenExclusivityError(mocha) → {Error}

Source:

Creates an error object to be thrown when .only() is used with
--forbid-only.

Parameters:
NameTypeDescription
mochaMocha

Mocha instance

Returns:
Type
Error

(static) createInvalidArgumentTypeError(message, argument, expected) → {Error}

Source:

Creates an error object to be thrown when an argument did not use the supported type

Parameters:
NameTypeDescription
messagestring

Error message to be displayed.

argumentstring

Argument name.

expectedstring

Expected argument datatype.

Returns:

instance detailing the error condition

Type
Error

(static) createInvalidArgumentValueError(message, argument, value, reasonopt) → {Error}

Source:

Creates an error object to be thrown when an argument did not use the supported value

Parameters:
NameTypeAttributesDescription
messagestring

Error message to be displayed.

argumentstring

Argument name.

valuestring

Argument value.

reasonstring<optional>

Why value is invalid.

Returns:

instance detailing the error condition

Type
Error

(static) createInvalidExceptionError(message) → {Error}

Source:

Creates an error object to be thrown when an exception was caught, but the Error is falsy or undefined.

Parameters:
NameTypeDescription
messagestring

Error message to be displayed.

Returns:

instance detailing the error condition

Type
Error

(static) createInvalidInterfaceError(message, ui) → {Error}

Source:

Creates an error object to be thrown when the interface specified in the options was not found.

Parameters:
NameTypeDescription
messagestring

Error message to be displayed.

uistring

User-specified interface value.

Returns:

instance detailing the error condition

Type
Error

(static) createInvalidLegacyPluginError(message, pluginType, pluginIdopt) → {Error}

Source:

Dynamically creates a plugin-type-specific error based on plugin type

Parameters:
NameTypeAttributesDescription
messagestring

Error message

pluginType"reporter" | "ui"

Plugin type. Future: expand as needed

pluginIdstring<optional>

Name/path of plugin, if any

Throws:

When pluginType is not known

Returns:
Type
Error

(static) createInvalidPluginDefinitionError(msg, pluginDefopt) → {Error}

Source:

Creates an error object to be thrown when a plugin definition is invalid

Parameters:
NameTypeAttributesDescription
msgstring

Error message

pluginDefPluginDefinition<optional>

Problematic plugin definition

Returns:
Type
Error

(static) createInvalidPluginError(message, pluginType, pluginIdopt) → {Error}

Source:
Deprecated:
  • Yes

DEPRECATED. Use createInvalidLegacyPluginError instead Dynamically creates a plugin-type-specific error based on plugin type

Parameters:
NameTypeAttributesDescription
messagestring

Error message

pluginType"reporter" | "interface"

Plugin type. Future: expand as needed

pluginIdstring<optional>

Name/path of plugin, if any

Throws:

When pluginType is not known

Returns:
Type
Error

(static) createInvalidPluginImplementationError(msg, optsopt) → {Error}

Source:

Creates an error object to be thrown when a plugin implementation (user code) is invalid

Parameters:
NameTypeAttributesDescription
msgstring

Error message

optsObject<optional>

Plugin definition and user-supplied implementation

Properties
NameTypeAttributesDescription
pluginDefPluginDefinition<optional>

Plugin Definition

pluginImpl*<optional>

Plugin Implementation (user-supplied)

Returns:
Type
Error

(static) createMissingArgumentError(message, argument, expected) → {Error}

Source:

Creates an error object to be thrown when an argument is missing.

Parameters:
NameTypeDescription
messagestring

Error message to be displayed.

argumentstring

Argument name.

expectedstring

Expected argument datatype.

Returns:

instance detailing the error condition

Type
Error

(static) createMochaInstanceAlreadyDisposedError(message, cleanReferencesAfterRun, instance)

Source:

Creates an error object to be thrown when a mocha object's run method is executed while it is already disposed.

Parameters:
NameTypeDescription
messagestring

The error message to be displayed.

cleanReferencesAfterRunboolean

the value of cleanReferencesAfterRun

instanceMocha

the mocha instance that throw this error

(static) createMochaInstanceAlreadyRunningError(message)

Source:

Creates an error object to be thrown when a mocha object's run method is called while a test run is in progress.

Parameters:
NameTypeDescription
messagestring

The error message to be displayed.

(static) createMultipleDoneError(runnable, originalErropt) → {Error}

Source:

Creates an error object to be thrown when done() is called multiple times in a test

Parameters:
NameTypeAttributesDescription
runnableRunnable

Original runnable

originalErrError<optional>

Original error, if any

Returns:

instance detailing the error condition

Type
Error

(static) createNoFilesMatchPatternError(message, pattern) → {Error}

Source:

Creates an error object to be thrown when no files to be tested could be found using specified pattern.

Parameters:
NameTypeDescription
messagestring

Error message to be displayed.

patternstring

User-specified argument value.

Returns:

instance detailing the error condition

Type
Error

(static) createTimeoutError(msg, timeoutopt, fileopt) → {MochaTimeoutError}

Source:

Creates an error object to be thrown when a runnable exceeds its allowed run time.

Parameters:
NameTypeAttributesDescription
msgstring

Error message

timeoutnumber<optional>

Timeout in ms

filestring<optional>

File, if given

Returns:
Type
MochaTimeoutError

(static) createUnparsableFileError(message, filename) → {Error}

Source:

Creates an error object to be thrown when file is unparsable

Parameters:
NameTypeDescription
messagestring

Error message to be displayed.

filenamestring

File name

Returns:
Type
Error

(static) createUnsupportedError(message) → {Error}

Source:

Creates an error object to be thrown when a behavior, option, or parameter is unsupported.

Parameters:
NameTypeDescription
messagestring

Error message to be displayed.

Returns:

instance detailing the error condition

Type
Error

(static) isMochaError(err) → {boolean}

Source:

Returns true if an error came out of Mocha.
Can suffer from false negatives, but not false positives.

Parameters:
NameTypeDescription
err*

Error, or anything

Returns:
Type
boolean

(inner) createInvalidReporterError(message, reporter) → {Error}

Source:

Creates an error object to be thrown when the reporter specified in the options was not found.

Parameters:
NameTypeDescription
messagestring

Error message to be displayed.

reporterstring

User-specified reporter value.

Returns:

instance detailing the error condition

Type
Error

Type Definitions

MochaTimeoutError

Source:
Properties:
NameTypeAttributesDescription
codeconstants.TIMEOUT

Error code

timeoutnumber<nullable>

Timeout in ms

filestring<nullable>

Filepath, if given

The error thrown when a Runnable times out

Type:
  • Error