Skip to content

Commit

Permalink
Merge pull request #124 from glennsarti/fix_rubocop
Browse files Browse the repository at this point in the history
(maint) Update for rubocop errors
  • Loading branch information
James Pogran authored May 13, 2019
2 parents 53ad68d + 916bc75 commit 916f8a7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions lib/puppet-editor-services/simple_tcp_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def fire_event
return false unless event
begin
event[0].call(*event[1])
rescue OpenSSL::SSL::SSLError => _
rescue OpenSSL::SSL::SSLError
log('SSL Bump - SSL Certificate refused?')
# rubocop:disable RescueException
rescue Exception => e
Expand Down Expand Up @@ -220,7 +220,7 @@ def io_review
if self.class.services[io]
begin
callback(self, :add_connection, io.accept_nonblock, self.class.services[io])
rescue Errno::EWOULDBLOCK => _ # rubocop:disable Lint/HandleExceptions
rescue Errno::EWOULDBLOCK # rubocop:disable Lint/HandleExceptions
# There's nothing to handle. Swallow the error
rescue StandardError => e
log(e.message)
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet-languageserver-sidecar/cache/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def load(absolute_path, section)
PuppetLanguageServerSidecar.log_message(:debug, "[PuppetLanguageServerSidecar::load] Loading #{absolute_path} from cache")

json_obj['data']
rescue RuntimeError => detail
PuppetLanguageServerSidecar.log_message(:debug, "[PuppetLanguageServerSidecar::load] Error loading #{absolute_path}: #{detail}")
rescue RuntimeError => e
PuppetLanguageServerSidecar.log_message(:debug, "[PuppetLanguageServerSidecar::load] Error loading #{absolute_path}: #{e}")
raise
end

Expand Down
30 changes: 15 additions & 15 deletions lib/puppet-languageserver-sidecar/puppet_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def self.retrieve_functions(cache, options = {})
if path_has_child?(options[:root_path], absolute_name) # rubocop:disable Style/IfUnlessModifier Nicer to read like this
funcs.concat(load_function_file(cache, name, absolute_name, autoloader, current_env))
end
rescue StandardError => err
PuppetLanguageServerSidecar.log_message(:error, "[PuppetHelper::load_functions] Error loading function #{file}: #{err} #{err.backtrace}")
rescue StandardError => e
PuppetLanguageServerSidecar.log_message(:error, "[PuppetHelper::load_functions] Error loading function #{file}: #{e} #{e.backtrace}")
end
end

Expand Down Expand Up @@ -137,8 +137,8 @@ def self.retrieve_types(cache, options = {})
if path_has_child?(options[:root_path], absolute_name) # rubocop:disable Style/IfUnlessModifier Nicer to read like this
types.concat(load_type_file(cache, name, absolute_name, autoloader, current_env))
end
rescue StandardError => err
PuppetLanguageServerSidecar.log_message(:error, "[PuppetHelper::retrieve_types] Error loading type #{file}: #{err} #{err.backtrace}")
rescue StandardError => e
PuppetLanguageServerSidecar.log_message(:error, "[PuppetHelper::retrieve_types] Error loading type #{file}: #{e} #{e.backtrace}")
end
end

Expand All @@ -165,8 +165,8 @@ def self.current_environment
return env unless env.nil?
rescue Puppet::Environments::EnvironmentNotFound
PuppetLanguageServerSidecar.log_message(:warning, "[PuppetHelper::current_environment] Unable to load environment #{Puppet.settings[:environment]}")
rescue StandardError => ex
PuppetLanguageServerSidecar.log_message(:warning, "[PuppetHelper::current_environment] Error loading environment #{Puppet.settings[:environment]}: #{ex}")
rescue StandardError => e
PuppetLanguageServerSidecar.log_message(:warning, "[PuppetHelper::current_environment] Error loading environment #{Puppet.settings[:environment]}: #{e}")
end
Puppet.lookup(:current_environment)
end
Expand Down Expand Up @@ -194,7 +194,7 @@ def self.load_classes_from_manifest(cache, manifest_file)
result = nil
begin
result = parser.parse_string(file_content, '')
rescue Puppet::ParseErrorWithIssue => _exception
rescue Puppet::ParseErrorWithIssue
# Any parsing errors means we can't inspect the document
return class_info
end
Expand Down Expand Up @@ -309,12 +309,12 @@ def self.load_type_file(cache, name, absolute_name, autoloader, env)
# will throw instead of not yielding.
begin
Puppet::Type.eachtype { |item| loaded_types << item.name }
rescue NoMethodError => detail
rescue NoMethodError => e
# Detect PUP-8301
if detail.respond_to?(:receiver)
raise unless detail.name == :each && detail.receiver.nil?
if e.respond_to?(:receiver)
raise unless e.name == :each && e.receiver.nil?
else
raise unless detail.name == :each && detail.message =~ /nil:NilClass/
raise unless e.name == :each && e.message =~ /nil:NilClass/
end
end

Expand All @@ -339,12 +339,12 @@ def self.load_type_file(cache, name, absolute_name, autoloader, env)
obj.calling_source = absolute_name
types << obj
end
rescue NoMethodError => detail
rescue NoMethodError => e
# Detect PUP-8301
if detail.respond_to?(:receiver)
raise unless detail.name == :each && detail.receiver.nil?
if e.respond_to?(:receiver)
raise unless e.name == :each && e.receiver.nil?
else
raise unless detail.name == :each && detail.message =~ /nil:NilClass/
raise unless e.name == :each && e.message =~ /nil:NilClass/
end
end
PuppetLanguageServerSidecar.log_message(:warn, "[PuppetHelper::load_type_file] type #{absolute_name} did not load any types") if types.empty?
Expand Down
36 changes: 18 additions & 18 deletions lib/puppet-languageserver/message_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def receive_request(request)
'fixesApplied' => changes,
'newContent' => changes > 0 || formatted_request.alwaysReturnContent ? new_content : nil
))
rescue StandardError => exception
PuppetLanguageServer.log_message(:error, "(puppet/fixDiagnosticErrors) #{exception}")
rescue StandardError => e
PuppetLanguageServer.log_message(:error, "(puppet/fixDiagnosticErrors) #{e}")
unless formatted_request.nil?
request.reply_result(LSP::PuppetFixDiagnosticErrorsResponse.new(
'documentUri' => formatted_request.documentUri,
Expand All @@ -112,8 +112,8 @@ def receive_request(request)
else
raise "Unable to provide completion on #{file_uri}"
end
rescue StandardError => exception
PuppetLanguageServer.log_message(:error, "(textDocument/completion) #{exception}")
rescue StandardError => e
PuppetLanguageServer.log_message(:error, "(textDocument/completion) #{e}")
request.reply_result(LSP::CompletionList.new('isIncomplete' => false, 'items' => []))
end

Expand All @@ -122,8 +122,8 @@ def receive_request(request)
request.reply_result(PuppetLanguageServer::Manifest::CompletionProvider.resolve(
LSP::CompletionItem.new(request.params)
))
rescue StandardError => exception
PuppetLanguageServer.log_message(:error, "(completionItem/resolve) #{exception}")
rescue StandardError => e
PuppetLanguageServer.log_message(:error, "(completionItem/resolve) #{e}")
# Spit back the same params if an error happens
request.reply_result(request.params)
end
Expand All @@ -140,8 +140,8 @@ def receive_request(request)
else
raise "Unable to provide hover on #{file_uri}"
end
rescue StandardError => exception
PuppetLanguageServer.log_message(:error, "(textDocument/hover) #{exception}")
rescue StandardError => e
PuppetLanguageServer.log_message(:error, "(textDocument/hover) #{e}")
request.reply_result(LSP::Hover.new)
end

Expand All @@ -157,8 +157,8 @@ def receive_request(request)
else
raise "Unable to provide definition on #{file_uri}"
end
rescue StandardError => exception
PuppetLanguageServer.log_message(:error, "(textDocument/definition) #{exception}")
rescue StandardError => e
PuppetLanguageServer.log_message(:error, "(textDocument/definition) #{e}")
request.reply_result(nil)
end

Expand All @@ -172,8 +172,8 @@ def receive_request(request)
else
raise "Unable to provide definition on #{file_uri}"
end
rescue StandardError => exception
PuppetLanguageServer.log_message(:error, "(textDocument/documentSymbol) #{exception}")
rescue StandardError => e
PuppetLanguageServer.log_message(:error, "(textDocument/documentSymbol) #{e}")
request.reply_result(nil)
end

Expand All @@ -182,16 +182,16 @@ def receive_request(request)
result = []
result.concat(PuppetLanguageServer::Manifest::DocumentSymbolProvider.workspace_symbols(request.params['query']))
request.reply_result(result)
rescue StandardError => exception
PuppetLanguageServer.log_message(:error, "(workspace/symbol) #{exception}")
rescue StandardError => e
PuppetLanguageServer.log_message(:error, "(workspace/symbol) #{e}")
request.reply_result([])
end

else
PuppetLanguageServer.log_message(:error, "Unknown RPC method #{request.rpc_method}")
end
rescue StandardError => err
PuppetLanguageServer::CrashDump.write_crash_file(err, nil, 'request' => request.rpc_method, 'params' => request.params)
rescue StandardError => e
PuppetLanguageServer::CrashDump.write_crash_file(e, nil, 'request' => request.rpc_method, 'params' => request.params)
raise
end

Expand Down Expand Up @@ -240,8 +240,8 @@ def receive_notification(method, params)
else
PuppetLanguageServer.log_message(:error, "Unknown RPC notification #{method}")
end
rescue StandardError => err
PuppetLanguageServer::CrashDump.write_crash_file(err, nil, 'notification' => method, 'params' => params)
rescue StandardError => e
PuppetLanguageServer::CrashDump.write_crash_file(e, nil, 'notification' => method, 'params' => params)
raise
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet_languageserver_sidecar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ def self.execute(options)
begin
manifest = File.open(options[:action_parameters]['source'], 'r:UTF-8') { |f| f.read }
PuppetLanguageServerSidecar::PuppetParserHelper.compile_node_graph(manifest)
rescue StandardError => ex
log_message(:error, "Unable to compile the manifest. #{ex}")
result.set_error("Unable to compile the manifest. #{ex}")
rescue StandardError => e
log_message(:error, "Unable to compile the manifest. #{e}")
result.set_error("Unable to compile the manifest. #{e}")
end

when 'resource_list'
Expand Down

0 comments on commit 916f8a7

Please sign in to comment.