fix: Add error handling for nonexistent file case with --file option#5086
Merged
JoshuaKGoldberg merged 29 commits intomochajs:mainfrom Jun 25, 2024
Merged
fix: Add error handling for nonexistent file case with --file option#5086JoshuaKGoldberg merged 29 commits intomochajs:mainfrom
JoshuaKGoldberg merged 29 commits intomochajs:mainfrom
Conversation
- added error handling when using the --file flag to do it the way --require does - added a test to assert that we throw the same type of error
|
|
- require.resolve() by Node.js follows a Node.js module resolution algo which includes checking if the resolved path actually exists on the file system.
JoshuaKGoldberg
requested changes
Mar 4, 2024
Member
JoshuaKGoldberg
left a comment
There was a problem hiding this comment.
Cool! 😎
Requesting changes on adding a bit more testing. But also let's talk about the direction a bit - I feel nervous adding in process.exit/throws deep within code. Thanks for sending!
khoaHyh
commented
Mar 24, 2024
khoaHyh
commented
May 29, 2024
Contributor
Author
khoaHyh
left a comment
There was a problem hiding this comment.
@JoshuaKGoldberg tagging for re-review just in case this disappeared into the backlog abyss 😅
JoshuaKGoldberg
approved these changes
Jun 25, 2024
Member
|
Note: I switched this to a |
Member
|
Thanks for stepping in and merging @JoshuaKGoldberg 🙏 🙂 |
This was referenced Jul 28, 2024
This was referenced Aug 7, 2024
This was referenced Oct 23, 2024
lennonnikolas
pushed a commit
to lennonnikolas/mocha
that referenced
this pull request
Jan 24, 2026
…ochajs#5086) * feat: handle nonexistent files passed to --file - added error handling when using the --file flag to do it the way --require does - added a test to assert that we throw the same type of error * refactor: remove path.resolve() - require.resolve() by Node.js follows a Node.js module resolution algo which includes checking if the resolved path actually exists on the file system. * add comment to new code in collect-files.js * fix: add back absolute path resolving * refactor: log warning and remove call stack * revert changes to bin/mocha.js * improve test case * throw error and have handler work with it * change collectFiles to return object * clean up * exit mocha immediately on missing file * new log message * add tests * code quality improvements * add comments * docs: update to new link name * pass mocha instance to helper function --------- Co-authored-by: Pelle Wessman <pelle@kodfabrik.se>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

🔎 Overview
Fixes #4047
--fileoption by resolving the argument to an absolute path and check for its existence. We now log a warning and exit if the file does not exist.--requirebubble up to the middleware inlib/cli/run.js. See here. This specific error occurs inlib/cli/run-helpers.jsin thesingleRunmethod when we load files asynchronously. Since we were lacking error handling there, the errors appeared the way they previously did before these changes.