From 1ec4ef9aa649083c55f60bdb7d2318118f79ad11 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Mon, 6 May 2024 14:04:36 +0900 Subject: [PATCH] Suppress `Interrupt` exception for LSP This PR suppresses the following backtrace of `Interrupt` exception for LSP: ## Before ```console $ bundle exec rubocop --lsp ^C/Users/koic/.rbenv/versions/3.4-dev/lib/ruby/gems/3.4.0+0/gems/language_server-protocol-3.17.0.3/ lib/language_server/protocol/transport/io/reader.rb:16:in 'IO#gets': Interrupt from /Users/koic/.rbenv/versions/3.4-dev/lib/ruby/gems/3.4.0+0/gems/language_server-protocol-3.17.0.3/ lib/language_server/protocol/transport/io/reader.rb:16:in 'LanguageServer::Protocol::Transport::Io::Reader#read' from /Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/lsp/server.rb:35:in 'RuboCop::LSP::Server#start' (snip) ``` ## After ```console $ bundle exec rubocop --lsp ^C Exiting... ``` --- lib/rubocop/cli.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/rubocop/cli.rb b/lib/rubocop/cli.rb index 18b818bfabfb..bc1c85469ede 100644 --- a/lib/rubocop/cli.rb +++ b/lib/rubocop/cli.rb @@ -57,6 +57,10 @@ def run(args = ARGV) rescue RuboCop::Error => e warn Rainbow("Error: #{e.message}").red STATUS_ERROR + rescue Interrupt + warn '' + warn 'Exiting...' + STATUS_INTERRUPTED rescue Finished STATUS_SUCCESS rescue OptionParser::InvalidOption => e