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:
Name Type Description
message string

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:
Name Type Description
mocha Mocha

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:
Name Type Description
message string

Error message to be displayed.

argument string

Argument name.

expected string

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:
Name Type Attributes Description
message string

Error message to be displayed.

argument string

Argument name.

value string

Argument value.

reason string <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:
Name Type Description
message string

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:
Name Type Description
message string

Error message to be displayed.

ui string

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:
Name Type Attributes Description
message string

Error message

pluginType "reporter" | "ui"

Plugin type. Future: expand as needed

pluginId string <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:
Name Type Attributes Description
msg string

Error message

pluginDef PluginDefinition <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:
Name Type Attributes Description
message string

Error message

pluginType "reporter" | "interface"

Plugin type. Future: expand as needed

pluginId string <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:
Name Type Attributes Description
msg string

Error message

opts Object <optional>

Plugin definition and user-supplied implementation

Properties
Name Type Attributes Description
pluginDef PluginDefinition <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:
Name Type Description
message string

Error message to be displayed.

argument string

Argument name.

expected string

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:
Name Type Description
message string

The error message to be displayed.

cleanReferencesAfterRun boolean

the value of cleanReferencesAfterRun

instance Mocha

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:
Name Type Description
message string

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:
Name Type Attributes Description
runnable Runnable

Original runnable

originalErr Error <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:
Name Type Description
message string

Error message to be displayed.

pattern string

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:
Name Type Attributes Description
msg string

Error message

timeout number <optional>

Timeout in ms

file string <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:
Name Type Description
message string

Error message to be displayed.

filename string

File name

Returns:

Error with code constants.UNPARSABLE_FILE

Type
Error

(static) createUnsupportedError(message) → {Error}

Source:

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

Parameters:
Name Type Description
message string

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:
Name Type Description
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:
Name Type Description
message string

Error message to be displayed.

reporter string

User-specified reporter value.

Returns:

instance detailing the error condition

Type
Error

Type Definitions

MochaTimeoutError

Source:
Properties:
Name Type Attributes Description
code constants.TIMEOUT

Error code

timeout number <nullable>

Timeout in ms

file string <nullable>

Filepath, if given

The error thrown when a Runnable times out

Type:
  • Error