Skip to content

Commit 53ad68d

Browse files
Merge pull request #119 from glennsarti/rubocop-fixes
(maint) Update for rubocop errors
2 parents 14a73f0 + fc84104 commit 53ad68d

File tree

14 files changed

+53
-50
lines changed

14 files changed

+53
-50
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,6 @@ Style/HashSyntax:
8080

8181
Layout/AlignHash:
8282
EnforcedHashRocketStyle: table
83+
84+
Naming/RescuedExceptionsVariableName:
85+
PreferredName: e

lib/puppet-debugserver/message_router.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@ def receive_request(request, original_json)
272272
}, request
273273
)
274274
@json_handler.send_response response
275-
rescue => exception # rubocop:disable Style/RescueStandardError
275+
rescue => e # rubocop:disable Style/RescueStandardError
276276
response = PuppetDebugServer::Protocol::Response.create_from_request(
277277
{
278278
'success' => false,
279-
'message' => exception.to_s
279+
'message' => e.to_s
280280
}, request
281281
)
282282
@json_handler.send_response response

lib/puppet-debugserver/puppet_debug_session.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ def self.start
173173
@puppet_thread = Thread.new do
174174
begin
175175
PuppetDebugServer::PuppetDebugSession.start_puppet
176-
rescue => err # rubocop:disable Style/RescueStandardError
177-
PuppetDebugServer.log_message(:error, "Error in Puppet Thread: #{err}")
176+
rescue => e # rubocop:disable Style/RescueStandardError
177+
PuppetDebugServer.log_message(:error, "Error in Puppet Thread: #{e}")
178178
raise
179179
end
180180
end
@@ -184,8 +184,8 @@ def self.start
184184
@watcher_thread = Thread.new do
185185
begin
186186
PuppetDebugServer::PuppetDebugSession.debug_session_watcher
187-
rescue => err # rubocop:disable Style/RescueStandardError
188-
PuppetDebugServer.log_message(:error, "Error in Watcher Thread: #{err}")
187+
rescue => e # rubocop:disable Style/RescueStandardError
188+
PuppetDebugServer.log_message(:error, "Error in Watcher Thread: #{e}")
189189
raise
190190
end
191191
end

lib/puppet-debugserver/puppet_monkey_patches.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ def self.compile(node, code_id = nil)
4949
PuppetDebugServer::PuppetDebugSession.hooks.exec_hook(:hook_after_compile, [result])
5050

5151
result
52-
rescue Puppet::ParseErrorWithIssue => detail
53-
detail.node = node.name
54-
Puppet.log_exception(detail)
52+
rescue Puppet::ParseErrorWithIssue => e
53+
e.node = node.name
54+
Puppet.log_exception(e)
5555
raise
56-
rescue => detail # rubocop:disable Style/RescueStandardError
57-
message = "#{detail} on node #{node.name}"
58-
Puppet.log_exception(detail, message)
59-
raise Puppet::Error, message, detail.backtrace
56+
rescue => e # rubocop:disable Style/RescueStandardError
57+
message = "#{e} on node #{node.name}"
58+
Puppet.log_exception(e, message)
59+
raise Puppet::Error, message, e.backtrace
6060
end
61-
rescue Puppet::ParseErrorWithIssue => detail
61+
rescue Puppet::ParseErrorWithIssue => e
6262
# TODO: Potential issue here with 4.10.x not implementing .file on the Positioned class
6363
# Just re-raise if there is no Puppet manifest file associated with the error
64-
raise if detail.file.nil? || detail.line.nil? || detail.pos.nil?
65-
PuppetDebugServer::PuppetDebugSession.hooks.exec_hook(:hook_exception, [detail])
64+
raise if e.file.nil? || e.line.nil? || e.pos.nil?
65+
PuppetDebugServer::PuppetDebugSession.hooks.exec_hook(:hook_exception, [e])
6666
raise
6767
end
6868
end

lib/puppet-languageserver-sidecar/puppet_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def self.retrieve_classes(cache, options = {})
5353
if path_has_child?(options[:root_path], manifest_file) # rubocop:disable Style/IfUnlessModifier Nicer to read like this
5454
classes.concat(load_classes_from_manifest(cache, manifest_file))
5555
end
56-
rescue StandardError => err
57-
PuppetLanguageServerSidecar.log_message(:error, "[PuppetHelper::retrieve_classes] Error loading manifest #{manifest_file}: #{err} #{err.backtrace}")
56+
rescue StandardError => e
57+
PuppetLanguageServerSidecar.log_message(:error, "[PuppetHelper::retrieve_classes] Error loading manifest #{manifest_file}: #{e} #{e.backtrace}")
5858
end
5959
end
6060
end

lib/puppet-languageserver-sidecar/puppet_parser_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def self.compile_node_graph(content)
1717
else
1818
result.dot_content = node_graph.to_dot(options)
1919
end
20-
rescue StandardError => exception
21-
result.set_error("Error while parsing the file. #{exception}")
20+
rescue StandardError => e
21+
result.set_error("Error while parsing the file. #{e}")
2222
end
2323

2424
result

lib/puppet-languageserver/epp/validation_provider.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ def self.validate(content, _max_problems = 100)
99
begin
1010
parser = Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new
1111
parser.parse_string(content, nil)
12-
rescue StandardError => detail
12+
rescue StandardError => e
1313
# Sometimes the error is in the cause not the root object itself
14-
detail = detail.cause if !detail.respond_to?(:line) && detail.respond_to?(:cause)
15-
ex_line = detail.respond_to?(:line) && !detail.line.nil? ? detail.line - 1 : nil # Line numbers from puppet exceptions are base 1
16-
ex_pos = detail.respond_to?(:pos) && !detail.pos.nil? ? detail.pos : nil # Pos numbers from puppet are base 1
14+
e = e.cause if !e.respond_to?(:line) && e.respond_to?(:cause)
15+
ex_line = e.respond_to?(:line) && !e.line.nil? ? e.line - 1 : nil # Line numbers from puppet exceptions are base 1
16+
ex_pos = e.respond_to?(:pos) && !e.pos.nil? ? e.pos : nil # Pos numbers from puppet are base 1
1717

18-
message = detail.respond_to?(:message) ? detail.message : nil
19-
message = detail.basic_message if message.nil? && detail.respond_to?(:basic_message)
18+
message = e.respond_to?(:message) ? e.message : nil
19+
message = e.basic_message if message.nil? && e.respond_to?(:basic_message)
2020

2121
unless ex_line.nil? || ex_pos.nil? || message.nil?
2222
result << LSP::Diagnostic.new('severity' => LSP::DiagnosticSeverity::ERROR,

lib/puppet-languageserver/facter_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ def self._load_facts
4848
begin
4949
Facter.loadfacts
5050
@fact_hash = Facter.to_hash
51-
rescue StandardError => ex
52-
PuppetLanguageServer.log_message(:error, "[FacterHelper::_load_facts] Error loading facts #{ex.message} #{ex.backtrace}")
53-
rescue LoadError => ex
54-
PuppetLanguageServer.log_message(:error, "[FacterHelper::_load_facts] Error loading facts (LoadError) #{ex.message} #{ex.backtrace}")
51+
rescue StandardError => e
52+
PuppetLanguageServer.log_message(:error, "[FacterHelper::_load_facts] Error loading facts #{e.message} #{e.backtrace}")
53+
rescue LoadError => e
54+
PuppetLanguageServer.log_message(:error, "[FacterHelper::_load_facts] Error loading facts (LoadError) #{e.message} #{e.backtrace}")
5555
end
5656
PuppetLanguageServer.log_message(:debug, "[FacterHelper::_load_facts] Finished loading #{@fact_hash.keys.count} facts")
5757
@facts_loaded = true

lib/puppet-languageserver/manifest/validation_provider.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def self.validate(content, options = {})
7979
end
8080
end
8181
# rubocop:disable Lint/HandleExceptions
82-
rescue StandardError => _exception
82+
rescue StandardError
8383
# If anything catastrophic happens we resort to puppet parsing anyway
8484
end
8585
# rubocop:enable Lint/HandleExceptions
@@ -101,14 +101,14 @@ def self.validate(content, options = {})
101101
Puppet[:tasks] = original_taskmode if Puppet.tasks_supported?
102102
end
103103
end
104-
rescue StandardError => detail
104+
rescue StandardError => e
105105
# Sometimes the error is in the cause not the root object itself
106-
detail = detail.cause if !detail.respond_to?(:line) && detail.respond_to?(:cause)
107-
ex_line = detail.respond_to?(:line) && !detail.line.nil? ? detail.line - 1 : nil # Line numbers from puppet exceptions are base 1
108-
ex_pos = detail.respond_to?(:pos) && !detail.pos.nil? ? detail.pos : nil # Pos numbers from puppet are base 1
106+
e = e.cause if !e.respond_to?(:line) && e.respond_to?(:cause)
107+
ex_line = e.respond_to?(:line) && !e.line.nil? ? e.line - 1 : nil # Line numbers from puppet exceptions are base 1
108+
ex_pos = e.respond_to?(:pos) && !e.pos.nil? ? e.pos : nil # Pos numbers from puppet are base 1
109109

110-
message = detail.respond_to?(:message) ? detail.message : nil
111-
message = detail.basic_message if message.nil? && detail.respond_to?(:basic_message)
110+
message = e.respond_to?(:message) ? e.message : nil
111+
message = e.basic_message if message.nil? && e.respond_to?(:basic_message)
112112

113113
unless ex_line.nil? || ex_pos.nil? || message.nil?
114114
result << LSP::Diagnostic.new('severity' => LSP::DiagnosticSeverity::ERROR,

lib/puppet-languageserver/puppet_parser_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def self.object_under_cursor(content, line_num, char_num, options)
116116
begin
117117
result = parser.singleton_parse_string(new_content, options[:tasks_mode], '')
118118
break
119-
rescue Puppet::ParseErrorWithIssue => _exception
119+
rescue Puppet::ParseErrorWithIssue
120120
next if options[:multiple_attempts]
121121
raise
122122
end
@@ -130,7 +130,7 @@ def self.object_under_cursor(content, line_num, char_num, options)
130130
# If during paring we modified the source we may need to change the cursor location
131131
begin
132132
line_offset = result.line_offsets[line_num]
133-
rescue StandardError => _e
133+
rescue StandardError
134134
line_offset = result['locator'].line_index[line_num]
135135
end
136136
# Typically we're completing after something was typed, so go back one char

0 commit comments

Comments
 (0)