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

Fix: don't classify plugins that throw errors as "missing" (fixes #6874) #8323

Merged
merged 2 commits into from Mar 30, 2017

Conversation

not-an-aardvark
Copy link
Member

@not-an-aardvark not-an-aardvark commented Mar 25, 2017

What is the purpose of this pull request? (put an "X" next to item)

[x] Bug fix (#6874)

What changes did you make? (Give an overview)

Previously, if a plugin threw an error on load, ESLint would display the "missing plugin" error message. This was confusing for plugin developers, because it would be difficult to distinguish between an installation error and a broken plugin.

This fix avoids the confusion by treating the errors as fatal and crashing with a stack trace if a plugin throws when it loads, as described in #7668 (comment).

Is there anything you'd like reviewers to focus on?

Nothing in particular

Previously, if a plugin threw an error on load, ESLint would display the "missing plugin" error message. This was confusing for plugin developers, because it would be difficult to distinguish between an installation error and a broken plugin.
@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly cli Relates to ESLint's command-line interface labels Mar 25, 2017
@mention-bot
Copy link

@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @nzakas, @mysticatea and @alberto to be potential reviewers.

@eslintbot
Copy link

LGTM

package.json Outdated
@@ -84,6 +84,7 @@
"ejs": "^2.5.6",
"eslint-plugin-eslint-plugin": "^0.7.1",
"eslint-plugin-node": "^4.2.1",
"eslint-plugin-throws-on-load": "^1.0.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't think of a good way to test the "throwing on load" behavior (proxyquire doesn't seem to support this case), so I just published a real plugin that throws on load for the purposes of this test.

Copy link
Member

Choose a reason for hiding this comment

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

Proxyquire supports mocking a dependency with any function. If you throw inside that function, it should work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried doing this:

diff --git a/tests/lib/config/plugins.js b/tests/lib/config/plugins.js
index 8bbff180..433cbeb8 100644
--- a/tests/lib/config/plugins.js
+++ b/tests/lib/config/plugins.js
@@ -43,7 +43,10 @@ describe("Plugins", () => {
                 "eslint-plugin-example": plugin,
                 "@scope/eslint-plugin-example": scopedPlugin,
                 "./environments": Environments,
-                "../rules": Rules
+                "../rules": Rules,
+                "eslint-plugin-throws-on-load"() {
+                    throw new Error("error thrown while loading this module");
+                }
             });
         });
 

But it doesn't work -- it seems like the function that throws an error is getting returned as the module rather than getting called. Is there another way to do it?

Copy link
Member

Choose a reason for hiding this comment

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

I think if you mock a dependency with a function that just means that the module exports a function.. I tried checking the docs of proxyquire and couldn't find any way to do some "initialization" logic before the stubbed exports object.

How about something with a getter, like this:

diff --git a/tests/lib/config/plugins.js b/tests/lib/config/plugins.js
index 8bbff18..f687343 100644
--- a/tests/lib/config/plugins.js
+++ b/tests/lib/config/plugins.js
@@ -42,6 +42,11 @@ describe("Plugins", () => {
             StubbedPlugins = proxyquire("../../../lib/config/plugins", {
                 "eslint-plugin-example": plugin,
                 "@scope/eslint-plugin-example": scopedPlugin,
+                "eslint-plugin-throws-on-load": {
+                    get rules() {
+                        throw new Error('error thrown while loading this module');
+                    }
+                },
                 "./environments": Environments,
                 "../rules": Rules
             });

I ran the tests locally and that seems to work, but it relies on the fact that the rules get registered when the plugin is loaded via Plugins.load.

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

Basically LGTM, but I'm hoping our best minds can find a different approach for testing.

@eslintbot
Copy link

LGTM

@not-an-aardvark not-an-aardvark merged commit 1b1046b into master Mar 30, 2017
@not-an-aardvark not-an-aardvark deleted the missing-plugin-errors branch March 30, 2017 00:41
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly cli Relates to ESLint's command-line interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants