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

Update: replace stacktrace by a clear message when invalid plugins are provided (fixes #10927) #10928

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
4 participants
@cotonne
Copy link

commented Oct 6, 2018

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

[ ] Documentation update
[X ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Tell us about your environment

  • ESLint Version: "eslint": "^5.6.1"
  • Node Version: v8.10.0
  • npm Version: 6.4.1

What parser (default, Babel-ESLint, etc.) are you using?

Please show your full configuration:

Configuration File eslintrc.json ```js { ... "plugins": [ ["import"], [{ "node": "node"}], { "promise": "promise" }], ] } ```

What did you do? Please include the actual source code causing the issue.
Provided an invalid json config file.
cf. configuration (generated with a fuzzer PyJFuzz)

What did you expect to happen?
A meaningful message should be displayed.

What actually happened? Please include the actual, raw output from ESLint.
Big exception:

TypeError: normalizedName.charAt is not a function
    at Object.normalizePackageName (xxx/node_modules/eslint/lib/util/naming.js:37:24)

What changes did you make? (Give an overview)
When a non-string parameter is provided to the configuration parameter "plugins",
an exception is thrown

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

@jsf-clabot

This comment has been minimized.

Copy link

commented Oct 6, 2018

CLA assistant check
All committers have signed the CLA.

@eslint eslint bot added the triage label Oct 6, 2018

@cotonne cotonne force-pushed the cotonne:issue10927 branch 3 times, most recently from 204f6f0 to fe1c838 Oct 6, 2018

@aladdin-add aladdin-add added bug core evaluating and removed triage labels Oct 6, 2018

@aladdin-add

This comment has been minimized.

Copy link
Member

commented Oct 6, 2018

thanks for the PR! 😄
I agreed it should output more friendly error message, but eslint is using schema validator ( ajv). I believe it's better to use it(like some other options). thoughts?

the config is here:

plugins: { type: "array" },

@aladdin-add aladdin-add added enhancement and removed bug labels Oct 6, 2018

@cotonne cotonne force-pushed the cotonne:issue10927 branch from fe1c838 to 96e0595 Oct 7, 2018

Fix: Clear message with invalid config "plugins" (fixes #10927)
When an invalid config type for "plugins" is provided in
eslintrc.json, like an array or an object, a stacktrace is
dumped.

The stacktrace has been replaced by a meaningful message
using ajv.

@cotonne cotonne force-pushed the cotonne:issue10927 branch from 96e0595 to 6eacde6 Oct 7, 2018

@cotonne

This comment has been minimized.

Copy link
Author

commented Oct 7, 2018

I fix the stacktrace by using the validation with ajv.

However, i duplicate a call to validator.validateConfigSchema into loadFromDisk (lib/config/config-file.js)

validateConfigSchema must be called before plugins.loadAll. Actually, the call is made by the function validator.validate.

I'm surprised by the fact that config is used before being validated.
Does it make sense to remove the call of validator.validateConfigSchema from the function validate?

@cotonne

This comment has been minimized.

Copy link
Author

commented Nov 2, 2018

Any comment on this fix?
Feel free to give me some feedbacks 😸

@nzakas nzakas changed the title Fix: replace stacktrace by a clear message when invalid plugins are provided (fixes #10927) Update: replace stacktrace by a clear message when invalid plugins are provided (fixes #10927) Dec 7, 2018

@nzakas

This comment has been minimized.

Copy link
Member

commented Dec 7, 2018

@cotonne sorry, we lost track of this.

Just to be clear: your concern here is if someone defines the plugins array with values other than strings, correct? In that case, you get an explosion at an unrelated point.

I agree that it would be nice to give a more useful error message to the user, though there must be a way to do that without validating twice.

@nzakas

This comment has been minimized.

Copy link
Member

commented Dec 7, 2018

After digging into this a bit, it looks like the best path forward might be to split up the validation steps in config-file.js such that the schema is validated first (as in this PR), and then we have a new method (something like, validateConfigContents() that is basically validate() without the config schema validation).

@not-an-aardvark @mysticatea thoughts on this?

@cotonne

This comment has been minimized.

Copy link
Author

commented Dec 7, 2018

@nzakas Yes, i duplicate the call mainly because it will break a lot of tests.
Clearly, this is a bad approach. I know that it is not the best method but I don't know enough eslint to propose a better way and what can be the impact.
I would appreciate to have some help with this issue.

@nzakas

This comment has been minimized.

Copy link
Member

commented Dec 14, 2018

@cotonne it seems like the team liked my last comment, so here's what I would suggest:

  • Create a validateConfigContents() method that is the same as validate() except that it does not do validateConfigSchema() first.
  • Export validateConfigContents() from config-validator.
  • Keep your call to validateConfigSchema() where it is, and change the following call to validate() to instead call validateConfigContents().

Does that make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.