Skip to content
This repository was 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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");'

var match = e.message.match(/^cannot find module '(.*)'/i);
if (match) { rethrow = (match[1] !== name); }
}
if (rethrow) { throw e; }
Expand Down