-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom error objects including code (#3467)
* add MochaError and use add missing E add codes to docs how to add new error E_ to ERR_ typo fix fix failing test typo fix * single custom object to multiple custom objects remove generic MochaError Use instance over code lint fix lint fix update references to suffix Error mocfix rebase * Remove custom errors, use factories Signed-off-by: Craig Taub <[email protected]> module name Errors remove superfluous error type. * add another reporter error * errors unit test * cleanup documentation * camelCase factories. Use props on errors. Use TypeError * test case use code * use TypeError for type issues * add full documentation. update error names * use code and message for reporter check * add error handling unit test for mocha * CLI to throw invalidArgumentValue error * add data type for MissingArgument error * updated suite test * use const for cli's errors * follow jsdoc for optional params
- Loading branch information
Showing
16 changed files
with
282 additions
and
43 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
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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
'use strict'; | ||
/** | ||
* @module Errors | ||
*/ | ||
/** | ||
* Factory functions to create throwable error objects | ||
*/ | ||
|
||
/** | ||
* Creates an error object used when no files to be tested could be found using specified pattern. | ||
* | ||
* @public | ||
* @param {string} message - Error message to be displayed. | ||
* @param {string} pattern - User-specified argument value. | ||
* @returns {Error} instance detailing the error condition | ||
*/ | ||
function createNoFilesMatchPatternError(message, pattern) { | ||
var err = new Error(message); | ||
err.code = 'ERR_MOCHA_NO_FILES_MATCH_PATTERN'; | ||
err.pattern = pattern; | ||
return err; | ||
} | ||
|
||
/** | ||
* Creates an error object used when the reporter specified in the options was not found. | ||
* | ||
* @public | ||
* @param {string} message - Error message to be displayed. | ||
* @param {string} reporter - User-specified reporter value. | ||
* @returns {Error} instance detailing the error condition | ||
*/ | ||
function createInvalidReporterError(message, reporter) { | ||
var err = new TypeError(message); | ||
err.code = 'ERR_MOCHA_INVALID_REPORTER'; | ||
err.reporter = reporter; | ||
return err; | ||
} | ||
|
||
/** | ||
* Creates an error object used when the interface specified in the options was not found. | ||
* | ||
* @public | ||
* @param {string} message - Error message to be displayed. | ||
* @param {string} ui - User-specified interface value. | ||
* @returns {Error} instance detailing the error condition | ||
*/ | ||
function createInvalidInterfaceError(message, ui) { | ||
var err = new Error(message); | ||
err.code = 'ERR_MOCHA_INVALID_INTERFACE'; | ||
err.interface = ui; | ||
return err; | ||
} | ||
|
||
/** | ||
* Creates an error object used when the type of output specified was not supported. | ||
* | ||
* @public | ||
* @param {string} message - Error message to be displayed. | ||
* @returns {Error} instance detailing the error condition | ||
*/ | ||
function createNotSupportedError(message) { | ||
var err = new Error(message); | ||
err.code = 'ERR_MOCHA_NOT_SUPPORTED'; | ||
return err; | ||
} | ||
|
||
/** | ||
* Creates an error object used when an argument is missing. | ||
* | ||
* @public | ||
* @param {string} message - Error message to be displayed. | ||
* @param {string} argument - Argument name. | ||
* @param {string} expected - Expected argument datatype. | ||
* @returns {Error} instance detailing the error condition | ||
*/ | ||
function createMissingArgumentError(message, argument, expected) { | ||
return createInvalidArgumentTypeError(message, argument, expected); | ||
} | ||
|
||
/** | ||
* Creates an error object used when an argument did not use the supported type | ||
* | ||
* @public | ||
* @param {string} message - Error message to be displayed. | ||
* @param {string} argument - Argument name. | ||
* @param {string} expected - Expected argument datatype. | ||
* @returns {Error} instance detailing the error condition | ||
*/ | ||
function createInvalidArgumentTypeError(message, argument, expected) { | ||
var err = new TypeError(message); | ||
err.code = 'ERR_MOCHA_INVALID_ARG_TYPE'; | ||
err.argument = argument; | ||
err.expected = expected; | ||
err.actual = typeof argument; | ||
return err; | ||
} | ||
|
||
/** | ||
* Creates an error object used when an argument did not use the supported value | ||
* | ||
* @public | ||
* @param {string} message - Error message to be displayed. | ||
* @param {string} argument - Argument name. | ||
* @param {string} value - Argument value. | ||
* @param {string} [reason] - Why value is invalid. | ||
* @returns {Error} instance detailing the error condition | ||
*/ | ||
function createInvalidArgumentValueError(message, argument, value, reason) { | ||
var err = new TypeError(message); | ||
err.code = 'ERR_MOCHA_INVALID_ARG_VALUE'; | ||
err.argument = argument; | ||
err.value = value; | ||
err.reason = typeof reason !== 'undefined' ? reason : 'is invalid'; | ||
return err; | ||
} | ||
|
||
/** | ||
* Creates an error object used when an error was thrown but no details were specified. | ||
* | ||
* @public | ||
* @param {string} message - Error message to be displayed. | ||
* @returns {Error} instance detailing the error condition | ||
*/ | ||
function createUndefinedError(message) { | ||
var err = new Error(message); | ||
err.code = 'ERR_MOCHA_UNDEFINED_ERROR'; | ||
return err; | ||
} | ||
|
||
module.exports = { | ||
createInvalidArgumentTypeError: createInvalidArgumentTypeError, | ||
createInvalidArgumentValueError: createInvalidArgumentValueError, | ||
createInvalidInterfaceError: createInvalidInterfaceError, | ||
createInvalidReporterError: createInvalidReporterError, | ||
createMissingArgumentError: createMissingArgumentError, | ||
createNoFilesMatchPatternError: createNoFilesMatchPatternError, | ||
createNotSupportedError: createNotSupportedError, | ||
createUndefinedError: createUndefinedError | ||
}; |
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
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
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
Oops, something went wrong.