-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added custom error objects including code #3467
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
02514bc
add MochaError and use
craigtaub 346aeee
single custom object to multiple custom objects
craigtaub 57d2e99
Remove custom errors, use factories
craigtaub 1d3b15e
add another reporter error
craigtaub 59b7368
errors unit test
craigtaub aa02b83
cleanup documentation
craigtaub 462a9ae
camelCase factories. Use props on errors. Use TypeError
craigtaub 356c8b1
test case use code
craigtaub 716e75f
use TypeError for type issues
craigtaub ddbb30e
add full documentation. update error names
craigtaub 5e69794
use code and message for reporter check
craigtaub 4ff2807
add error handling unit test for mocha
craigtaub b754a53
CLI to throw invalidArgumentValue error
craigtaub b478d6f
add data type for MissingArgument error
craigtaub 2088133
updated suite test
craigtaub 3c2f725
use const for cli's errors
craigtaub 713533d
follow jsdoc for optional params
craigtaub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
*/ | ||
|
||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Creates an error object used when no files to be tested could be found using specified pattern. | ||
* | ||
* @public | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a later revision (PR), we should generate the messages using additional arguments rather than requiring the caller to do so. var err = new Error(`{message}: pattern: "{pattern}"`); But let's get what you've done thusfar in place first... |
||
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); | ||
} | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* 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); | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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; | ||
} | ||
|
||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* 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, | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
createInvalidArgumentValueError: createInvalidArgumentValueError, | ||
createInvalidInterfaceError: createInvalidInterfaceError, | ||
createInvalidReporterError: createInvalidReporterError, | ||
createMissingArgumentError: createMissingArgumentError, | ||
createNoFilesMatchPatternError: createNoFilesMatchPatternError, | ||
createNotSupportedError: createNotSupportedError, | ||
createUndefinedError: createUndefinedError | ||
}; | ||
plroebuck marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
future PR: use variables instead of hardcoded strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regrettably, it's the standard Node
Error.code
processing pattern.This seems more like what I would have preferred -- exported constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I had it like that on first iteration of PR but the change was lost in the ether. Will look at updating.