Skip to content

Commit

Permalink
fix: rescue StandardError for rubocop fail
Browse files Browse the repository at this point in the history
  • Loading branch information
snutij committed Sep 20, 2023
1 parent aa73fb2 commit f030e5c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/ruby_lsp/requests/support/rubocop_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ class InternalRuboCopError < StandardError
extend T::Sig

MESSAGE = <<~EOS
An internal error occurred for the %s cop.
An internal error occurred %s.
Updating to a newer version of RuboCop may solve this.
For more details, run RuboCop on the command line.
EOS

sig { params(rubocop_error: RuboCop::ErrorWithAnalyzedFileLocation).void }
sig { params(rubocop_error: T.any(RuboCop::ErrorWithAnalyzedFileLocation, StandardError)).void }
def initialize(rubocop_error)
message = format(MESSAGE, rubocop_error.cop.name)
message = case rubocop_error
when RuboCop::ErrorWithAnalyzedFileLocation
format(MESSAGE, "for the #{rubocop_error.cop.name} cop")
when StandardError
format(MESSAGE, rubocop_error.message)
end
super(message)
end
end
Expand Down Expand Up @@ -87,7 +92,7 @@ def run(path, contents)
raise Formatting::Error, error.message
rescue RuboCop::ValidationError => error
raise ConfigurationError, error.message
rescue RuboCop::ErrorWithAnalyzedFileLocation => error
rescue StandardError => error
raise InternalRuboCopError, error
end

Expand Down

0 comments on commit f030e5c

Please sign in to comment.