Skip to content

Commit 1160aa8

Browse files
committed
(PUP-11993) Style/RaiseArgs
This commit enables the Style/RaiseArgs cop and fixes 253 autocorrectable offenses.
1 parent 2bc53e6 commit 1160aa8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+253
-308
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,12 +646,6 @@ Style/OptionalBooleanParameter:
646646
Style/PreferredHashMethods:
647647
Enabled: false
648648

649-
# This cop supports safe auto-correction (--auto-correct).
650-
# Configuration parameters: EnforcedStyle, AllowedCompactTypes.
651-
# SupportedStyles: compact, exploded
652-
Style/RaiseArgs:
653-
Enabled: false
654-
655649
# This cop supports safe auto-correction (--auto-correct).
656650
Style/RedundantAssignment:
657651
Exclude:

lib/puppet/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def find(application_name)
251251
################################################################
252252

253253
if clazz.nil?
254-
raise Puppet::Error.new(_("Unable to load application class '%{class_name}' from file 'puppet/application/%{application_name}.rb'") % { class_name: class_name, application_name: application_name })
254+
raise Puppet::Error, _("Unable to load application class '%{class_name}' from file 'puppet/application/%{application_name}.rb'") % { class_name: class_name, application_name: application_name }
255255
end
256256

257257
return clazz

lib/puppet/application/face_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def parse_options
105105
if option
106106
index += 1 if option[:argument] and !(option[:optional])
107107
else
108-
raise OptionParser::InvalidOption.new(item.sub(/=.*$/, ''))
108+
raise OptionParser::InvalidOption, item.sub(/=.*$/, '')
109109
end
110110
end
111111
end

lib/puppet/application/ssl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def submit_request(ssl_context)
192192
Puppet.notice _("Submitted certificate request for '%{name}' to %{url}") % { name: Puppet[:certname], url: route.url }
193193
rescue Puppet::HTTP::ResponseError => e
194194
if e.response.code == 400
195-
raise Puppet::Error.new(_("Could not submit certificate request for '%{name}' to %{url} due to a conflict on the server") % { name: Puppet[:certname], url: route.url })
195+
raise Puppet::Error, _("Could not submit certificate request for '%{name}' to %{url} due to a conflict on the server") % { name: Puppet[:certname], url: route.url }
196196
else
197197
raise Puppet::Error.new(_("Failed to submit certificate request: %{message}") % { message: e.message }, e)
198198
end

lib/puppet/configurer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def valid_server_environment?
536536
rescue Puppet::HTTP::ResponseError => detail
537537
if detail.response.code == 404
538538
if Puppet[:strict_environment_mode]
539-
raise Puppet::Error.new(_("Environment '%{environment}' not found on server, aborting run.") % { environment: @environment })
539+
raise Puppet::Error, _("Environment '%{environment}' not found on server, aborting run.") % { environment: @environment }
540540
else
541541
Puppet.notice(_("Environment '%{environment}' not found on server, skipping initial pluginsync.") % { environment: @environment })
542542
end

lib/puppet/configurer/downloader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def evaluate
2020
if first_failure
2121
event = (first_failure.events || []).first
2222
detail = event ? event.message : 'unknown'
23-
raise Puppet::Error.new(_("Failed to retrieve %{name}: %{detail}") % { name: name, detail: detail })
23+
raise Puppet::Error, _("Failed to retrieve %{name}: %{detail}") % { name: name, detail: detail }
2424
end
2525
end
2626

lib/puppet/file_bucket/file.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ def initialize(contents, options = {})
2626
when Pathname
2727
@contents = FileContents.new(contents)
2828
else
29-
raise ArgumentError.new(_("contents must be a String or Pathname, got a %{contents_class}") % { contents_class: contents.class })
29+
raise ArgumentError, _("contents must be a String or Pathname, got a %{contents_class}") % { contents_class: contents.class }
3030
end
3131

3232
@bucket_path = options.delete(:bucket_path)
3333
@checksum_type = Puppet[:digest_algorithm].to_sym
34-
raise ArgumentError.new(_("Unknown option(s): %{opts}") % { opts: options.keys.join(', ') }) unless options.empty?
34+
raise ArgumentError, _("Unknown option(s): %{opts}") % { opts: options.keys.join(', ') } unless options.empty?
3535
end
3636

3737
# @return [Num] The size of the contents

lib/puppet/file_serving/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def links=(value)
5959
attr_reader :path
6060

6161
def path=(path)
62-
raise ArgumentError.new(_("Paths must be fully qualified")) unless Puppet::FileServing::Base.absolute?(path)
62+
raise ArgumentError, _("Paths must be fully qualified") unless Puppet::FileServing::Base.absolute?(path)
6363

6464
@path = path
6565
end
@@ -69,7 +69,7 @@ def path=(path)
6969
attr_reader :relative_path
7070

7171
def relative_path=(path)
72-
raise ArgumentError.new(_("Relative paths must not be fully qualified")) if Puppet::FileServing::Base.absolute?(path)
72+
raise ArgumentError, _("Relative paths must not be fully qualified") if Puppet::FileServing::Base.absolute?(path)
7373

7474
@relative_path = path
7575
end

lib/puppet/file_serving/configuration/parser.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ def parse
4343
end
4444
else
4545
error_location_str = Puppet::Util::Errors.error_location(@file.filename, @count)
46-
raise ArgumentError.new(_("Invalid argument '%{var}' at %{error_location}") %
47-
{ var: var, error_location: error_location_str })
46+
raise ArgumentError, _("Invalid argument '%{var}' at %{error_location}") %
47+
{ var: var, error_location: error_location_str }
4848
end
4949
else
5050
error_location_str = Puppet::Util::Errors.error_location(@file.filename, @count)
51-
raise ArgumentError.new(_("Invalid entry at %{error_location}: '%{file_text}'") %
52-
{ file_text: line.chomp, error_location: error_location_str })
51+
raise ArgumentError, _("Invalid entry at %{error_location}: '%{file_text}'") %
52+
{ file_text: line.chomp, error_location: error_location_str }
5353
end
5454
end
5555
end
@@ -73,8 +73,8 @@ def changed?
7373
def newmount(name)
7474
if @mounts.include?(name)
7575
error_location_str = Puppet::Util::Errors.error_location(@file, @count)
76-
raise ArgumentError.new(_("%{mount} is already mounted at %{name} at %{error_location}") %
77-
{ mount: @mounts[name], name: name, error_location: error_location_str })
76+
raise ArgumentError, _("%{mount} is already mounted at %{name} at %{error_location}") %
77+
{ mount: @mounts[name], name: name, error_location: error_location_str }
7878
end
7979
case name
8080
when "modules"

lib/puppet/file_serving/fileset.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def initialize(path, options = {})
3333
else
3434
path = path.chomp(File::SEPARATOR) unless path == File::SEPARATOR
3535
end
36-
raise ArgumentError.new(_("Fileset paths must be fully qualified: %{path}") % { path: path }) unless Puppet::Util.absolute_path?(path)
36+
raise ArgumentError, _("Fileset paths must be fully qualified: %{path}") % { path: path } unless Puppet::Util.absolute_path?(path)
3737

3838
@path = path
3939

@@ -50,9 +50,9 @@ def initialize(path, options = {})
5050
initialize_from_hash(options)
5151
end
5252

53-
raise ArgumentError.new(_("Fileset paths must exist")) unless valid?(path)
53+
raise ArgumentError, _("Fileset paths must exist") unless valid?(path)
5454
# TRANSLATORS "recurse" and "recurselimit" are parameter names and should not be translated
55-
raise ArgumentError.new(_("Fileset recurse parameter must not be a number anymore, please use recurselimit")) if @recurse.is_a?(Integer)
55+
raise ArgumentError, _("Fileset recurse parameter must not be a number anymore, please use recurselimit") if @recurse.is_a?(Integer)
5656
end
5757

5858
# Return a list of all files in our fileset. This is different from the
@@ -68,7 +68,7 @@ def files
6868
munged_max_files = max_files == '-1' ? -1 : max_files
6969

7070
if munged_max_files > 0 && files.size > munged_max_files
71-
raise Puppet::Error.new _("The directory '%{path}' contains %{entries} entries, which exceeds the limit of %{munged_max_files} specified by the max_files parameter for this resource. The limit may be increased, but be aware that large number of file resources can result in excessive resource consumption and degraded performance. Consider using an alternate method to manage large directory trees") % { path: path, entries: files.size, munged_max_files: munged_max_files }
71+
raise Puppet::Error, _("The directory '%{path}' contains %{entries} entries, which exceeds the limit of %{munged_max_files} specified by the max_files parameter for this resource. The limit may be increased, but be aware that large number of file resources can result in excessive resource consumption and degraded performance. Consider using an alternate method to manage large directory trees") % { path: path, entries: files.size, munged_max_files: munged_max_files }
7272
elsif munged_max_files == 0 && files.size > soft_max_files
7373
Puppet.warning _("The directory '%{path}' contains %{entries} entries, which exceeds the default soft limit %{soft_max_files} and may cause excessive resource consumption and degraded performance. To remove this warning set a value for `max_files` parameter or consider using an alternate method to manage large directory trees") % { path: path, entries: files.size, soft_max_files: soft_max_files }
7474
end

0 commit comments

Comments
 (0)