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 #10977] Add option to raise cop errors, --raise-cop-error #11001

Merged
merged 2 commits into from Oct 24, 2022

Conversation

wildmaples
Copy link
Contributor

@wildmaples wildmaples commented Sep 13, 2022

Fix #10977

We want to be able to rescue cop-related errors.

There exists :raise_error, but it's used for internal tests such as through cop helper.

I added a new option that raises with RuboCop::ErrorWithAnalyzedFileLocation, which surfaces more information.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@wildmaples wildmaples changed the title Add option to raise cop errors Add option to raise cop errors, --raise-cop-error Sep 13, 2022
@wildmaples wildmaples force-pushed the option-for-cop-errors branch 2 times, most recently from df0693b to ca89e57 Compare September 13, 2022 15:51
@wildmaples wildmaples changed the title Add option to raise cop errors, --raise-cop-error [Fix #10977] Add option to raise cop errors, --raise-cop-error Sep 13, 2022
@dvandersluis
Copy link
Member

I'm not sure I understand the use case for this? Why do you want rubocop to stop when an error is raised? (Which shouldn't happen in normal operation, of course)

Also there's already --debug which will output errors/backtraces when an exception is encountered.

@wildmaples
Copy link
Contributor Author

Hi @dvandersluis, thanks for taking a look at this!!

We need this option to rescue any cop exceptions when running RuboCop on the Ruby LSP for a better use experience. The TL;DR is that we want to make sure users know there is an error (instead of failing silently using --debug which is what we are doing now) because it prevents the file from being processed while open on VS Code.

We have a more detailed issue you can find here: Shopify/ruby-lsp#250

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 29, 2022

I see. That makes sense to me, but it has to be documented very clearly.

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 20, 2022

@wildmaples Ping :-)

wildmaples and others added 2 commits October 20, 2022 12:16
There was no option to get granular cop-related error. Previously, we only had :raise_error, which is used to test exceptions internally.

This change adds a user-facing option to raise cop-related errors, while maintaining the internal :raise_error option.
@wildmaples
Copy link
Contributor Author

Thanks for the reminder, @bbatsov!

I've added some copy mentioning the new option in the Cop and Basic Usage section of the Rubocop documentation. I also provided additional context for to describe the option. (b165c59)

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 23, 2022

Looks good. I'll include merge this after cutting the next bugfix release.

@bbatsov bbatsov merged commit 7797192 into rubocop:master Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to surface more informative cop errors
3 participants