Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ Style/HashSyntax:

Layout/AlignHash:
EnforcedHashRocketStyle: table

Naming/RescuedExceptionsVariableName:
PreferredName: e
4 changes: 2 additions & 2 deletions lib/puppet-debugserver/message_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ def receive_request(request, original_json)
}, request
)
@json_handler.send_response response
rescue => exception # rubocop:disable Style/RescueStandardError
rescue => e # rubocop:disable Style/RescueStandardError
response = PuppetDebugServer::Protocol::Response.create_from_request(
{
'success' => false,
'message' => exception.to_s
'message' => e.to_s
}, request
)
@json_handler.send_response response
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet-debugserver/puppet_debug_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def self.start
@puppet_thread = Thread.new do
begin
PuppetDebugServer::PuppetDebugSession.start_puppet
rescue => err # rubocop:disable Style/RescueStandardError
PuppetDebugServer.log_message(:error, "Error in Puppet Thread: #{err}")
rescue => e # rubocop:disable Style/RescueStandardError
PuppetDebugServer.log_message(:error, "Error in Puppet Thread: #{e}")
raise
end
end
Expand All @@ -184,8 +184,8 @@ def self.start
@watcher_thread = Thread.new do
begin
PuppetDebugServer::PuppetDebugSession.debug_session_watcher
rescue => err # rubocop:disable Style/RescueStandardError
PuppetDebugServer.log_message(:error, "Error in Watcher Thread: #{err}")
rescue => e # rubocop:disable Style/RescueStandardError
PuppetDebugServer.log_message(:error, "Error in Watcher Thread: #{e}")
raise
end
end
Expand Down
20 changes: 10 additions & 10 deletions lib/puppet-debugserver/puppet_monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ def self.compile(node, code_id = nil)
PuppetDebugServer::PuppetDebugSession.hooks.exec_hook(:hook_after_compile, [result])

result
rescue Puppet::ParseErrorWithIssue => detail
detail.node = node.name
Puppet.log_exception(detail)
rescue Puppet::ParseErrorWithIssue => e
e.node = node.name
Puppet.log_exception(e)
raise
rescue => detail # rubocop:disable Style/RescueStandardError
message = "#{detail} on node #{node.name}"
Puppet.log_exception(detail, message)
raise Puppet::Error, message, detail.backtrace
rescue => e # rubocop:disable Style/RescueStandardError
message = "#{e} on node #{node.name}"
Puppet.log_exception(e, message)
raise Puppet::Error, message, e.backtrace
end
rescue Puppet::ParseErrorWithIssue => detail
rescue Puppet::ParseErrorWithIssue => e
# TODO: Potential issue here with 4.10.x not implementing .file on the Positioned class
# Just re-raise if there is no Puppet manifest file associated with the error
raise if detail.file.nil? || detail.line.nil? || detail.pos.nil?
PuppetDebugServer::PuppetDebugSession.hooks.exec_hook(:hook_exception, [detail])
raise if e.file.nil? || e.line.nil? || e.pos.nil?
PuppetDebugServer::PuppetDebugSession.hooks.exec_hook(:hook_exception, [e])
raise
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet-languageserver-sidecar/puppet_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def self.retrieve_classes(cache, options = {})
if path_has_child?(options[:root_path], manifest_file) # rubocop:disable Style/IfUnlessModifier Nicer to read like this
classes.concat(load_classes_from_manifest(cache, manifest_file))
end
rescue StandardError => err
PuppetLanguageServerSidecar.log_message(:error, "[PuppetHelper::retrieve_classes] Error loading manifest #{manifest_file}: #{err} #{err.backtrace}")
rescue StandardError => e
PuppetLanguageServerSidecar.log_message(:error, "[PuppetHelper::retrieve_classes] Error loading manifest #{manifest_file}: #{e} #{e.backtrace}")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet-languageserver-sidecar/puppet_parser_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def self.compile_node_graph(content)
else
result.dot_content = node_graph.to_dot(options)
end
rescue StandardError => exception
result.set_error("Error while parsing the file. #{exception}")
rescue StandardError => e
result.set_error("Error while parsing the file. #{e}")
end

result
Expand Down
12 changes: 6 additions & 6 deletions lib/puppet-languageserver/epp/validation_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ def self.validate(content, _max_problems = 100)
begin
parser = Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new
parser.parse_string(content, nil)
rescue StandardError => detail
rescue StandardError => e
# Sometimes the error is in the cause not the root object itself
detail = detail.cause if !detail.respond_to?(:line) && detail.respond_to?(:cause)
ex_line = detail.respond_to?(:line) && !detail.line.nil? ? detail.line - 1 : nil # Line numbers from puppet exceptions are base 1
ex_pos = detail.respond_to?(:pos) && !detail.pos.nil? ? detail.pos : nil # Pos numbers from puppet are base 1
e = e.cause if !e.respond_to?(:line) && e.respond_to?(:cause)
ex_line = e.respond_to?(:line) && !e.line.nil? ? e.line - 1 : nil # Line numbers from puppet exceptions are base 1
ex_pos = e.respond_to?(:pos) && !e.pos.nil? ? e.pos : nil # Pos numbers from puppet are base 1

message = detail.respond_to?(:message) ? detail.message : nil
message = detail.basic_message if message.nil? && detail.respond_to?(:basic_message)
message = e.respond_to?(:message) ? e.message : nil
message = e.basic_message if message.nil? && e.respond_to?(:basic_message)

unless ex_line.nil? || ex_pos.nil? || message.nil?
result << LSP::Diagnostic.new('severity' => LSP::DiagnosticSeverity::ERROR,
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet-languageserver/facter_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def self._load_facts
begin
Facter.loadfacts
@fact_hash = Facter.to_hash
rescue StandardError => ex
PuppetLanguageServer.log_message(:error, "[FacterHelper::_load_facts] Error loading facts #{ex.message} #{ex.backtrace}")
rescue LoadError => ex
PuppetLanguageServer.log_message(:error, "[FacterHelper::_load_facts] Error loading facts (LoadError) #{ex.message} #{ex.backtrace}")
rescue StandardError => e
PuppetLanguageServer.log_message(:error, "[FacterHelper::_load_facts] Error loading facts #{e.message} #{e.backtrace}")
rescue LoadError => e
PuppetLanguageServer.log_message(:error, "[FacterHelper::_load_facts] Error loading facts (LoadError) #{e.message} #{e.backtrace}")
end
PuppetLanguageServer.log_message(:debug, "[FacterHelper::_load_facts] Finished loading #{@fact_hash.keys.count} facts")
@facts_loaded = true
Expand Down
14 changes: 7 additions & 7 deletions lib/puppet-languageserver/manifest/validation_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def self.validate(content, options = {})
end
end
# rubocop:disable Lint/HandleExceptions
rescue StandardError => _exception
rescue StandardError
# If anything catastrophic happens we resort to puppet parsing anyway
end
# rubocop:enable Lint/HandleExceptions
Expand All @@ -101,14 +101,14 @@ def self.validate(content, options = {})
Puppet[:tasks] = original_taskmode if Puppet.tasks_supported?
end
end
rescue StandardError => detail
rescue StandardError => e
# Sometimes the error is in the cause not the root object itself
detail = detail.cause if !detail.respond_to?(:line) && detail.respond_to?(:cause)
ex_line = detail.respond_to?(:line) && !detail.line.nil? ? detail.line - 1 : nil # Line numbers from puppet exceptions are base 1
ex_pos = detail.respond_to?(:pos) && !detail.pos.nil? ? detail.pos : nil # Pos numbers from puppet are base 1
e = e.cause if !e.respond_to?(:line) && e.respond_to?(:cause)
ex_line = e.respond_to?(:line) && !e.line.nil? ? e.line - 1 : nil # Line numbers from puppet exceptions are base 1
ex_pos = e.respond_to?(:pos) && !e.pos.nil? ? e.pos : nil # Pos numbers from puppet are base 1

message = detail.respond_to?(:message) ? detail.message : nil
message = detail.basic_message if message.nil? && detail.respond_to?(:basic_message)
message = e.respond_to?(:message) ? e.message : nil
message = e.basic_message if message.nil? && e.respond_to?(:basic_message)

unless ex_line.nil? || ex_pos.nil? || message.nil?
result << LSP::Diagnostic.new('severity' => LSP::DiagnosticSeverity::ERROR,
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet-languageserver/puppet_parser_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def self.object_under_cursor(content, line_num, char_num, options)
begin
result = parser.singleton_parse_string(new_content, options[:tasks_mode], '')
break
rescue Puppet::ParseErrorWithIssue => _exception
rescue Puppet::ParseErrorWithIssue
next if options[:multiple_attempts]
raise
end
Expand All @@ -130,7 +130,7 @@ def self.object_under_cursor(content, line_num, char_num, options)
# If during paring we modified the source we may need to change the cursor location
begin
line_offset = result.line_offsets[line_num]
rescue StandardError => _e
rescue StandardError
line_offset = result['locator'].line_index[line_num]
end
# Typically we're completing after something was typed, so go back one char
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet-languageserver/puppetfile/validation_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ def self.validate(content, _max_problems = 100)
begin
puppetfile = PuppetLanguageServer::Puppetfile::R10K::Puppetfile.new
puppetfile.load!(content)
rescue StandardError, SyntaxError, LoadError => detail
rescue StandardError, SyntaxError, LoadError => e
# Find the originating error from within the puppetfile
loc = detail.backtrace_locations
.select { |item| item.absolute_path == PuppetLanguageServer::Puppetfile::R10K::PUPPETFILE_MONIKER }
.first
loc = e.backtrace_locations
.select { |item| item.absolute_path == PuppetLanguageServer::Puppetfile::R10K::PUPPETFILE_MONIKER }
.first
start_line_number = loc.nil? ? 0 : loc.lineno - 1 # Line numbers from ruby are base 1
end_line_number = loc.nil? ? content.lines.count - 1 : loc.lineno - 1 # Line numbers from ruby are base 1
# Note - Ruby doesn't give a character position so just highlight the entire line
result << LSP::Diagnostic.new('severity' => LSP::DiagnosticSeverity::ERROR,
'range' => LSP.create_range(start_line_number, 0, end_line_number, max_line_length),
'source' => 'Puppet',
'message' => detail.to_s)
'message' => e.to_s)

puppetfile = nil
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet-languageserver/sidecar_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def enqueue(action, additional_args)
@queue_threads << Thread.new do
begin
worker
rescue => err # rubocop:disable Style/RescueStandardError
PuppetLanguageServer.log_message(:error, "Error in SidecarQueue Thread: #{err}")
rescue => e # rubocop:disable Style/RescueStandardError
PuppetLanguageServer.log_message(:error, "Error in SidecarQueue Thread: #{e}")
raise
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet-languageserver/validation_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def self.enqueue(file_uri, doc_version, connection_object)
@queue_thread = Thread.new do
begin
worker
rescue => err # rubocop:disable Style/RescueStandardError
PuppetLanguageServer.log_message(:error, "Error in ValidationQueue Thread: #{err}")
rescue => e # rubocop:disable Style/RescueStandardError
PuppetLanguageServer.log_message(:error, "Error in ValidationQueue Thread: #{e}")
raise
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet_languageserver_sidecar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def self.parse(options)
begin
ap.from_json!(json_string)
args[:action_parameters] = ap
rescue StandardError => ex
raise "Unable to parse the action parameters: #{ex}"
rescue StandardError => e
raise "Unable to parse the action parameters: #{e}"
end
end

Expand Down