Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Update regex to handle newer exception message #96

Merged
merged 1 commit into from
Feb 15, 2020

Conversation

percyhanna
Copy link
Contributor

The exception message has apparently changed in newer version of Node.

Fix for #95.

The exception message has apparently changed in newer version of Node.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 34274c4 on percyhanna:patch-1 into ccbfec8 on wbyoung:master.

@@ -109,7 +109,7 @@ exports.first = function(predicate) {
rethrowUnlessFailedRequire = function(name, e) {
var rethrow = true;
if (e.code === 'MODULE_NOT_FOUND') {
var match = e.message.match(/^cannot find module '(.*)'$/i);
Copy link

Choose a reason for hiding this comment

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

What's an old vs a new error message look like?

node's errors have a code property that's far more reliable than using the message (in node versions that have the code). Could we prefer using that, and fall back to message-based heuristics?

Copy link
Contributor Author

@percyhanna percyhanna Feb 13, 2020

Choose a reason for hiding this comment

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

The code is already being used on the previous line. The regex is being used to confirm that the missing module is actually the plugin trying to be loaded, not some other dependency (that's my assumption, anyway).

Test command:

node -r 'require("foo");'

Node v12.4.1:

Error: Cannot find module 'require("foo");'
Require stack:
- internal/preload

Node v8.15.1:

Error: Cannot find module 'require("foo");'

@wbyoung
Copy link
Owner

wbyoung commented Feb 15, 2020

I'm going to merge this, but would like to get all the CI builds passing again before releasing a new version. I don't have a ton of time to work on this right now though, so if you're interested in messing around with that, feel free.

@wbyoung wbyoung merged commit 5a130ba into wbyoung:master Feb 15, 2020
@percyhanna percyhanna deleted the patch-1 branch June 5, 2020 17:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants