KEMBAR78
Gracefully handle invalid configs during LSP addon startup by Earlopain · Pull Request #14508 · rubocop/rubocop · GitHub
Skip to content

Conversation

@Earlopain
Copy link
Contributor

If the config is invalid for any reason during startup, the addon will be left in a state which it cannot recover from.
This fixes this by instead showing a notification to the user. After the config is fixed, it will be properly reloaded. While it is invalid, no diagnostics will be shown.

I have also:

  • Removed reliance on RubyLsp::Requests::Support::InternalRuboCopError
  • Moved lsp specific error handling into the addon itself
  • Logged the full error

The main goal was to gracefully handle editing the config, where it may be invalid shortly, however due to a ruby-lsp bug no feedback is given in that case yet.


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.


raise(TypeError, "Malformed configuration in #{absolute_path}") unless hash.is_a?(Hash)
unless hash.is_a?(Hash)
raise(ValidationError, "Malformed configuration in #{absolute_path}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

in ConfigLoader, ValidationError is raised when some values don't have the expected shape. This makes it consistent and allows it to be rescued more specifically in reload_config

"- #{e.message}"
end
raise Requests::Formatting::Error, <<~MSG
An internal error occurred #{message}.
Copy link
Contributor Author

@Earlopain Earlopain Sep 5, 2025

Choose a reason for hiding this comment

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

I talked with @vinistock recently, and the reason for inlining this is that they eventually want to deprecate/remove the formatter on the ruby-lsp side. So we should not rely on RubyLsp::Requests::Support::InternalRuboCopError being around.

I also want to completly stop loading the ruby-lsp buildin addon in the future, in which case it would also not be defined.

If the config is invalid for any reason during startup, the addon will be left in a state
which it cannot recover from.
This fixes this by instead showing a notification to the user.
After the config is fixed, it will be properly reloaded.
While it is invalid, no diagnostics will be shown.

I have also:
* Removed reliance on `RubyLsp::Requests::Support::InternalRuboCopError`
* Moved lsp specific error handling into the addon itself
* Logged the full error

The main goal was to gracefully handle editing the config,
where it may be invalid shortly, however due to a ruby-lsp bug no feedback is given in that case yet.
@koic koic merged commit 9fb210b into rubocop:master Sep 8, 2025
22 checks passed
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.

2 participants