Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature: Improve error message reported by getParserServices #8482

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

Closed
disaacson opened this issue Feb 15, 2024 · 8 comments · Fixed by #8484
Closed

Feature: Improve error message reported by getParserServices #8482

disaacson opened this issue Feb 15, 2024 · 8 comments · Fixed by #8484
Labels
accepting prs Go ahead, send a pull request that resolves this issue locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. repo maintenance things to do with maintenance of the repo, and not with code/docs

Comments

@disaacson
Copy link
Contributor

disaacson commented Feb 15, 2024

Suggestion

I'm getting an error from this line
https://github.com/typescript-eslint/typescript-eslint/blame/18c3216485c381dd0215cfa7099f33bc721c8efe/packages/utils/src/eslint-utils/getParserServices.ts#L93

Error: Error while loading rule '@typescript-eslint/no-base-to-string': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward "parserOptions.project" to @typescript-eslint/parser.

I would like to submit a pull request to include in the error message the parserPath value that is causing the error. That could help with debugging this issue when it arises.

@disaacson disaacson added repo maintenance things to do with maintenance of the repo, and not with code/docs triage Waiting for team members to take a look labels Feb 15, 2024
@bradzacher
Copy link
Member

Could you please provide some more info here - what usecase are you looking to improve by adding the parser path?

I personally am not convinced that it's a good thing based on the usecases I know of and would think the extra information would be noise in those cases - so I'm going to need some more information from you.

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for team members to take a look labels Feb 15, 2024
@disaacson
Copy link
Contributor Author

I've had to debug this issue and it is difficult in a large monorepo project without knowing that value. As the error is about, or based on, that specific value, it would be very helpful information in debugging that error when it occurs.

@bradzacher
Copy link
Member

As the error is about, or based on, that specific value

Sorry that's the part I don't understand.
How is the error about the parser path?

How would knowing that the parser path is node_modules/@typescript-eslint/dist/index.js help?

Could you please describe how knowing that would have helped you debug?

@disaacson
Copy link
Contributor Author

disaacson commented Feb 15, 2024

Here is the output when linting the project:

Error: Error while loading rule '@typescript-eslint/no-base-to-string': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward Occurred while linting /Users/derrick/code/borderless-web/packages/utils-shared-configs/package.json
   at throwError (/Users/derrick/code/borderless-web/packages/utils-shared-configs/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:39:11)
   at getParserServices (/Users/derrick/code/borderless-web/packages/utils-shared-configs/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:23:9)
   at create (/Users/derrick/code/borderless-web/packages/utils-shared-configs/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-base-to-string.js:69:55)
   at Object.create (/Users/derrick/code/borderless-web/packages/utils-shared-configs/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:38:20)
   at createRuleListeners (/Users/derrick/code/borderless-web/node_modules/eslint/lib/linter/linter.js:895:21)
   at /Users/derrick/code/borderless-web/node_modules/eslint/lib/linter/linter.js:1066:110
   at Array.forEach (<anonymous>)
   at runRules (/Users/derrick/code/borderless-web/node_modules/eslint/lib/linter/linter.js:1003:34)
   at Linter._verifyWithoutProcessors (/Users/derrick/code/borderless-web/node_modules/eslint/lib/linter/linter.js:1355:31)
   at Linter._verifyWithoutProcessors (/Users/derrick/code/borderless-web/node_modules/eslint-plugin-eslint-comments/lib/utils/patch.js:166:36)
error Command failed with exit code 2.

It says detected a parser other than @typescript-eslint/parser, but it does not say which one. The project is configured to use @typescript-eslint/parser, so it is confusing. If the error said what this other parser is that is the cause of the error, it could help the developer identify which parser is being found in place of the supposedly configured one.

In short, it refers to this "other" parser as being the cause of the error. It would be very helpful to know which one is unintentially being found. That would aid in tracking down the root cause to the error.

I am happy to submit a pull request for this change, and to take any feedback on the pull request.

@disaacson
Copy link
Contributor Author

disaacson commented Feb 15, 2024

Using the example in the automated test for that error, it would now output

You have used a rule which requires parserServices to be generated. You must therefore provide a value for the \"parserOptions.project\" property for @typescript-eslint/parser.
Parser: @babel/parser.js
Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward \"parserOptions.project\" to @typescript-eslint/parser.

The information that the parser it found was @babel/parser.js can help track down the cause of the error.

@JoshuaKGoldberg
Copy link
Member

Seems reasonable to me to mention the parser explicitly. The downside is having a bit more verbose of a log, but the upside of being more explicit & clear can IMO help folks figure out where things are going wrong. So, what disaacson said. 😄

cc @bradzacher - thoughts?

@bradzacher
Copy link
Member

sure sounrds good

@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed awaiting response Issues waiting for a reply from the OP or another party labels Feb 25, 2024
@disaacson
Copy link
Contributor Author

I updated the PR's checklist. Let me know if you have any feedback or requested changes. Thanks!
https://github.com/typescript-eslint/typescript-eslint/pull/8484/files

@JoshuaKGoldberg JoshuaKGoldberg changed the title Repo: Improve error message reported by getParserServices Feature: Improve error message reported by getParserServices Feb 27, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2024
@bradzacher bradzacher added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. repo maintenance things to do with maintenance of the repo, and not with code/docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants