Skip to content
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

Create Module not found error #4826

Closed
wants to merge 1 commit into from
Closed

Conversation

sciffany
Copy link

@sciffany sciffany commented Feb 7, 2022

Requirements

  • Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • All new code requires tests to ensure against regressions.

Description of the Change

In this PR, we throw the "Module Not Found" error when a non-existent module is being imported in the config file. Before this was introduced, an unhelpful message of "Unparsable File Error" is being thrown, which may confuse the users. This aims to resolve issue #4781

Alternate Designs

The alternative would be to ignore the "Module Not Found" error, and just display these errors as "Unparsable File". But "Module Not Found" should not be under "Unparsable File" since "Unparsable File" implies that there might be a syntax error somewhere in the program.

Why should this be in core?

This should be in the core because one of the main functionalities of Mocha is to show the users the correct error messages.

Benefits

A more helpful error message will be shown to users of Mocha, which leads to less confusion when using this package.

Possible Drawbacks

There are no drawbacks to this change, unless maybe if some old users are not used to seeing this new error message.

Applicable issues

Not a breaking change
This is an enhancement.
It should not impact production code.

Other notes: Hi, I am a new contributor :) Thank you very much for reviewing!

Copy link
Member

@juergba juergba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't understood yet how you are going to solve this issue.

`${filepath} is attempting to import a module that does not exist: ${err}`,
filepath
);
}
Copy link
Member

@juergba juergba Feb 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me how you are going to distinguish module not found errors caused by invalid path (see parsers) and by invalid imports.

* @param {string} importedFilename - File name of imported module
* @returns {Error} Error with code {@link constants.MODULE_NOT_FOUND}
*/
function createModuleNotFoundError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a new Mocha error code, we can't wrap each and every Node error in a new Mocha error object. We just have to rethrow Node's error somehow or include Node's error message in Mocha's UnparsableFileError object.

@@ -5,7 +5,6 @@
"requires": true,
"packages": {
"": {
"name": "mocha",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct here. There shouldn't be any package-lock.json entry in this PR.

@juergba
Copy link
Member

juergba commented Feb 13, 2022

Error: Unable to read/parse ./test/.mocharc.cjs: Error: Cannot find module './test/.mocharc.cjs'

It's not the first part which is wrong, but the second error message. It should be:
Error: Unable to read/parse ./test/.mocharc.cjs: Error: Cannot find module '0a9g'

@juergba
Copy link
Member

juergba commented Feb 17, 2022

superseded by #4832

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants