Skip to content

Commit

Permalink
Correct RuboCop Style/RescueStandardError offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
quatran committed Aug 25, 2020
1 parent a5d527b commit b6c6e5d
Show file tree
Hide file tree
Showing 19 changed files with 23 additions and 48 deletions.
25 changes: 0 additions & 25 deletions src/api/.rubocop_todo.yml
Expand Up @@ -1333,31 +1333,6 @@ Style/OptionalBooleanParameter:
- 'app/policies/package_policy.rb'
- 'lib/xpath_engine.rb'

# Offense count: 23
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, explicit
Style/RescueStandardError:
Exclude:
- 'app/controllers/search_controller.rb'
- 'app/controllers/source_controller.rb'
- 'app/controllers/statistics_controller.rb'
- 'app/controllers/webui/feeds_controller.rb'
- 'app/controllers/webui/package_controller.rb'
- 'app/controllers/webui/projects/rebuild_times_controller.rb'
- 'app/helpers/validation_helper.rb'
- 'app/lib/backend/file.rb'
- 'app/models/package.rb'
- 'app/models/project_log_entry.rb'
- 'app/models/service.rb'
- 'app/models/update_notification_events.rb'
- 'app/models/user.rb'
- 'app/models/user_ldap_strategy.rb'
- 'db/migrate/20140721112346_delayed_job_indexes.rb'
- 'lib/rabbitmq_bus.rb'
- 'lib/tasks/dev.rake'
- 'lib/tasks/extract.rake'

# Offense count: 307
# Cop supports --auto-correct.
Style/StringConcatenation:
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/controllers/search_controller.rb
Expand Up @@ -126,12 +126,12 @@ def predicate_from_match_parameter(p)
def filter_items(items)
begin
@offset = Integer(params[:offset])
rescue
rescue StandardError
@offset = 0
end
begin
@limit = Integer(params[:limit])
rescue
rescue StandardError
@limit = items.size
end
nitems = []
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/source_controller.rb
Expand Up @@ -600,7 +600,7 @@ def project_command_move
project.store(commit)
# update meta data in all packages, they contain the project name as well
project.packages.each { |package| package.store(commit) }
rescue
rescue StandardError
render_error status: 400, errorcode: 'move_failed',
message: 'Move operation failed'
return
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/statistics_controller.rb
Expand Up @@ -60,7 +60,7 @@ def rating
rating.object_id = object.id
rating.user_id = User.session!.id
rating.save
rescue
rescue StandardError
render_error status: 400, errorcode: 'error setting rating',
message: 'rating not saved'
return
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/controllers/webui/feeds_controller.rb
Expand Up @@ -40,13 +40,13 @@ def notifications

def starting_at(date)
Time.zone.parse(date)
rescue
rescue StandardError
7.days.ago
end

def ending_at(date)
Time.zone.parse(date)
rescue
rescue StandardError
nil
end
end
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/package_controller.rb
Expand Up @@ -889,7 +889,7 @@ def set_job_status
ld = js.get('lastduration')
@percent = (@buildtime * 100) / ld.to_i if ld.present?
end
rescue
rescue StandardError
@workerid = nil
@buildtime = nil
end
Expand Down
Expand Up @@ -80,7 +80,7 @@ def call_diststats(bdep, jobs)
f = File.open(outdir + '/rebuild.png')
png = f.read
f.close
rescue
rescue StandardError
return
end
Rails.cache.write("rebuild-#{@pngkey}.png", png)
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/helpers/validation_helper.rb
Expand Up @@ -29,7 +29,7 @@ def validate_read_access_of_deleted_package(project, name)

begin
revisions_list = Backend::Api::Sources::Package.revisions(project, name)
rescue
rescue StandardError
raise Package::UnknownObjectError, "Package not found: #{project}/#{name}"
end
data = Xmlhash.parse(revisions_list)
Expand All @@ -49,7 +49,7 @@ def validate_read_access_of_deleted_package(project, name)
def validate_visibility_of_deleted_project(project)
begin
revisions_list = Backend::Api::Sources::Project.revisions(project)
rescue
rescue StandardError
raise Project::UnknownObjectError, "Project not found: #{project}"
end
data = Xmlhash.parse(revisions_list)
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/lib/backend/file.rb
Expand Up @@ -49,7 +49,7 @@ def file(query = {})
@last_read_query = query
end
@file
rescue => e
rescue StandardError => e
@backend_file_errors = e.message
valid?
nil
Expand Down Expand Up @@ -88,7 +88,7 @@ def save!(query = {}, content = nil)
# Tries to save the file to the backend. Returns nil if some StandardError is raised
def save(query = {}, content = nil)
save!(query, content)
rescue => e
rescue StandardError => e
@backend_file_errors = e.message
valid?
nil
Expand All @@ -105,7 +105,7 @@ def destroy!(query = {})
# Tries to destroy the file from the backend. Returns nil if some StandardError is raised
def destroy(query = {})
destroy!(query)
rescue => e
rescue StandardError => e
@backend_file_errors = e.message
valid?
nil
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/package.rb
Expand Up @@ -598,7 +598,7 @@ def update_product_list
Product.transaction do
begin
xml = Xmlhash.parse(Backend::Connection.get(source_path(nil, view: :products)).body)
rescue
rescue StandardError
return
end
xml.elements('productdefinition') do |pd|
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/project_log_entry.rb
Expand Up @@ -51,7 +51,7 @@ def user
# reach us through Event...
def additional_info=(obj)
self[:additional_info] = YAML.dump(obj)[0..65_534]
rescue
rescue StandardError
self[:additional_info] = nil
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/service.rb
Expand Up @@ -45,7 +45,7 @@ def addDownloadURL(url, filename = nil)

begin
uri = URI.parse(url)
rescue
rescue StandardError
return false
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/update_notification_events.rb
Expand Up @@ -22,7 +22,7 @@ def create_events
retries -= 1
retry if retries.positive?
Airbrake.notify("Failed to create Event : #{type.inspect}: #{data} #{e}")
rescue => e
rescue StandardError => e
if Rails.env.test?
# make debug output useful in test suite, not just showing backtrace to Airbrake
Rails.logger.error "ERROR: #{e.inspect}: #{e.backtrace}"
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/user.rb
Expand Up @@ -192,7 +192,7 @@ def self.find_with_credentials_via_ldap(login, password)
ldap_info = UserLdapStrategy.find_with_ldap(login, password)
rescue LoadError
logger.warn "ldap_mode selected but 'ruby-ldap' module not installed."
rescue
rescue StandardError
logger.debug "#{login} not found in LDAP."
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/models/user_ldap_strategy.rb
Expand Up @@ -167,7 +167,7 @@ def self.dn2user_principal_name(dn)
dn_uid = dn_components.select { |x, _| x == 'uid' }.map! { |_, y| y }
dn_path = dn_components.select { |x, _| x == 'dc' }.map! { |_, y| y }
upn = "#{dn_uid.fetch(0)}@#{dn_path.join('.')}"
rescue
rescue StandardError
# if we run into unexpected input just return an empty string
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/db/migrate/20140721112346_delayed_job_indexes.rb
Expand Up @@ -4,7 +4,7 @@ def up

add_index :delayed_jobs, :locked_at
add_index :delayed_jobs, :queue
rescue
rescue StandardError
# we had a wrong migration id first
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/rabbitmq_bus.rb
Expand Up @@ -12,7 +12,7 @@ def self.send_to_bus(channel, data)
self.failed = true
publish(channel, data)
end
rescue => e
rescue StandardError => e
Rails.logger.error "Publishing to RabbitMQ failed: #{e.message}"
Airbrake.notify(e)
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/tasks/dev.rake
Expand Up @@ -33,7 +33,7 @@ namespace :dev do
puts 'Creating the database...'
begin
Rake::Task['db:version'].invoke
rescue
rescue StandardError
Rake::Task['db:setup'].invoke
if args.old_test_suite
puts 'Old test suite. Loading fixtures...'
Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/tasks/extract.rake
Expand Up @@ -41,7 +41,7 @@ namespace :db do
oldhash ||= {}
rescue Errno::ENOENT, TypeError
oldhash = {}
rescue => e
rescue StandardError => e
puts e.class
raise e
end
Expand Down

0 comments on commit b6c6e5d

Please sign in to comment.