From b6c2b6750a64bb60944180766c8ce9237341def1 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 8 May 2015 16:09:24 +0200 Subject: [PATCH] Corrected with rubocop cop 'Lint/RescueException'. --- .rubocop.yml | 2 -- app/controllers/application_controller.rb | 10 +++++----- app/controllers/getting_started_controller.rb | 12 ++++++------ app/controllers/long_polling_controller.rb | 2 +- app/controllers/users_controller.rb | 4 ++-- app/models/channel.rb | 2 +- app/models/channel/email_parser.rb | 4 ++-- app/models/channel/email_send.rb | 2 +- app/models/channel/filter/database.rb | 2 +- app/models/channel/imap.rb | 2 +- app/models/channel/twitter2.rb | 2 +- lib/auth/ldap.rb | 2 +- lib/cache.rb | 2 +- lib/rss.rb | 2 +- lib/sessions.rb | 2 +- lib/time_calculation.rb | 2 +- lib/user_agent.rb | 8 ++++---- 17 files changed, 30 insertions(+), 32 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 982ce1c25..e9867b6a0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -193,7 +193,5 @@ Style/Documentation: Description: 'Document classes and non-namespace modules.' Enabled: false -Lint/RescueException: - Enabled: false Lint/UselessAssignment: Enabled: false diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ff1a0e815..247d5d316 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -287,7 +287,7 @@ class ApplicationController < ActionController::Base generic_object.param_set_associations( params ) model_create_render_item(generic_object) - rescue Exception => e + rescue => e logger.error e.message logger.error e.backtrace.inspect render json: { error: e.message }, status: :unprocessable_entity @@ -309,7 +309,7 @@ class ApplicationController < ActionController::Base generic_object.param_set_associations( params ) model_update_render_item( generic_object ) - rescue Exception => e + rescue => e logger.error e.message logger.error e.backtrace.inspect render json: { error: e.message }, status: :unprocessable_entity @@ -323,7 +323,7 @@ class ApplicationController < ActionController::Base generic_object = object.find( params[:id] ) generic_object.destroy model_destory_render_item() - rescue Exception => e + rescue => e logger.error e.message logger.error e.backtrace.inspect render json: { error: e.message }, status: :unprocessable_entity @@ -343,7 +343,7 @@ class ApplicationController < ActionController::Base generic_object = object.find( params[:id] ) model_show_render_item(generic_object) - rescue Exception => e + rescue => e logger.error e.message logger.error e.backtrace.inspect render json: { error: e.message }, status: :unprocessable_entity @@ -356,7 +356,7 @@ class ApplicationController < ActionController::Base def model_index_render (object, _params) generic_objects = object.all model_index_render_result( generic_objects ) - rescue Exception => e + rescue => e logger.error e.message logger.error e.backtrace.inspect render json: { error: e.message }, status: :unprocessable_entity diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb index c0f8486dc..f8e799ab2 100644 --- a/app/controllers/getting_started_controller.rb +++ b/app/controllers/getting_started_controller.rb @@ -628,7 +628,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} else found = Channel::POP3.new.fetch( { options: params[:inbound][:options] }, 'verify', subject ) end - rescue Exception => e + rescue => e render json: { result: 'invalid', message: e.to_s, @@ -762,7 +762,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} options: params[:options] } ) - rescue Exception => e + rescue => e # check if sending email was ok, but mailserver rejected if !subject @@ -806,7 +806,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} mail, nil ) - rescue Exception => e + rescue => e message_human = '' translation_map.each {|key, message| if e.message =~ /#{Regexp.escape(key)}/i @@ -846,7 +846,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} begin Channel::IMAP.new.fetch( { options: params[:options] }, 'check' ) - rescue Exception => e + rescue => e message_human = '' translation_map.each {|key, message| if e.message =~ /#{Regexp.escape(key)}/i @@ -869,7 +869,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} begin Channel::POP3.new.fetch( { options: params[:options] }, 'check' ) - rescue Exception => e + rescue => e message_human = '' translation_map.each {|key, message| if e.message =~ /#{Regexp.escape(key)}/i @@ -896,7 +896,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} ress = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) ress.map { |r| [r.exchange.to_s, IPSocket.getaddress(r.exchange.to_s), r.preference] } end - rescue Exception => e + rescue => e logger.error e.message logger.error e.backtrace.inspect end diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index 777236c37..8f292cbbb 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -137,7 +137,7 @@ class LongPollingController < ApplicationController return end end - rescue Exception => e + rescue => e logger.error e.inspect logger.error e.backtrace render json: { error: 'Invalid client_id in receive loop!' }, status: :unprocessable_entity diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ba7601971..76754df6c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -176,7 +176,7 @@ class UsersController < ApplicationController user_new = User.find( user.id ) render json: user_new, status: :created - rescue Exception => e + rescue => e render json: { error: e.message }, status: :unprocessable_entity end end @@ -220,7 +220,7 @@ class UsersController < ApplicationController # get new data user_new = User.find( params[:id] ) render json: user_new, status: :ok - rescue Exception => e + rescue => e render json: { error: e.message }, status: :unprocessable_entity end end diff --git a/app/models/channel.rb b/app/models/channel.rb index c97236be1..79716bbae 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -9,7 +9,7 @@ class Channel < ApplicationModel begin c = eval 'Channel::' + channel[:adapter].upcase + '.new' # rubocop:disable Lint/Eval c.fetch(channel) - rescue Exception => e + rescue => e logger.error "can't use " + 'Channel::' + channel[:adapter].upcase logger.error e.inspect logger.error e.backtrace diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 98b432b64..f5de75dab 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -338,7 +338,7 @@ class Channel::EmailParser filters.each {|_prio, backend| begin backend.run( channel, mail ) - rescue Exception => e + rescue => e Rails.logger.error "can't run postmaster pre filter #{backend}" Rails.logger.error e.inspect return false @@ -487,7 +487,7 @@ class Channel::EmailParser filters.each {|_prio, backend| begin backend.run( channel, mail, ticket, article, user ) - rescue Exception => e + rescue => e Rails.logger.error "can't run postmaster post filter #{backend}" Rails.logger.error e.inspect end diff --git a/app/models/channel/email_send.rb b/app/models/channel/email_send.rb index 507a1e4c5..97601772f 100644 --- a/app/models/channel/email_send.rb +++ b/app/models/channel/email_send.rb @@ -8,7 +8,7 @@ module Channel::EmailSend begin c = eval 'Channel::' + channel[:adapter] + '.new' # rubocop:disable Lint/Eval c.send(attr, channel, notification) - rescue Exception => e + rescue => e Rails.logger.error "can't use " + 'Channel::' + channel[:adapter] Rails.logger.error e.inspect Rails.logger.error e.backtrace diff --git a/app/models/channel/filter/database.rb b/app/models/channel/filter/database.rb index a03a2ee1e..1c1ad6a34 100644 --- a/app/models/channel/filter/database.rb +++ b/app/models/channel/filter/database.rb @@ -25,7 +25,7 @@ module Channel::Filter::Database Rails.logger.info " is not matching #{ key.downcase }:'#{ mail[ key.downcase.to_sym ] }' on #{value}" match = false end - rescue Exception => e + rescue => e match = false Rails.logger.error "can't use match rule #{value} on #{mail[ key.to_sym ]}" Rails.logger.error e.inspect diff --git a/app/models/channel/imap.rb b/app/models/channel/imap.rb index f62701236..ccf230016 100644 --- a/app/models/channel/imap.rb +++ b/app/models/channel/imap.rb @@ -29,7 +29,7 @@ class Channel::IMAP < Channel::EmailParser # try LOGIN, if not - try plain begin @imap.authenticate( 'LOGIN', channel[:options][:user], channel[:options][:password] ) - rescue Exception => e + rescue => e if e.to_s !~ /(unsupported\s(authenticate|authentication)\smechanism|not\ssupported)/i raise e end diff --git a/app/models/channel/twitter2.rb b/app/models/channel/twitter2.rb index 7f0856a76..331d8160c 100644 --- a/app/models/channel/twitter2.rb +++ b/app/models/channel/twitter2.rb @@ -112,7 +112,7 @@ class Channel::TWITTER2 elsif tweet.respond_to?('from_user_id') begin sender = @client.user(tweet.from_user_id) - rescue Exception => e + rescue => e Rails.logger.error 'Exception: twitter: ' + e.inspect return end diff --git a/lib/auth/ldap.rb b/lib/auth/ldap.rb index 836def97f..5581defe0 100644 --- a/lib/auth/ldap.rb +++ b/lib/auth/ldap.rb @@ -21,7 +21,7 @@ module Auth::Ldap Rails.logger.info "Can't bind to '#{config[:host]}', #{ldap.get_operation_result.code}, #{ldap.get_operation_result.message}" return end - rescue Exception => e + rescue => e Rails.logger.info "Can't connect to '#{config[:host]}', #{e}" return end diff --git a/lib/cache.rb b/lib/cache.rb index ae0603ea5..d4b0aad02 100644 --- a/lib/cache.rb +++ b/lib/cache.rb @@ -32,7 +32,7 @@ write a cache end begin Rails.cache.write( key.to_s, data, params) - rescue Exception => e + rescue => e Rails.logger.error "NOTICE: #{e.message}" end end diff --git a/lib/rss.rb b/lib/rss.rb index ec90fdcb4..d83ce8f2d 100644 --- a/lib/rss.rb +++ b/lib/rss.rb @@ -27,7 +27,7 @@ module Rss break item if fetched == limit.to_i } Cache.write( cache_key, items, expires_in: 4.hours ) - rescue Exception => e + rescue => e Rails.logger.error "can't fetch #{url}" Rails.logger.error e.inspect return diff --git a/lib/sessions.rb b/lib/sessions.rb index 8d421e70c..e3e9c9a53 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -266,7 +266,7 @@ returns data[:user] = data_json['user'] # for compat. reasons end } - rescue Exception => e + rescue => e Rails.logger.error e.inspect destory(client_id) Rails.logger.error "ERROR: reading session file '#{session_file}', remove session." diff --git a/lib/time_calculation.rb b/lib/time_calculation.rb index 50898fadc..5c99190a2 100644 --- a/lib/time_calculation.rb +++ b/lib/time_calculation.rb @@ -23,7 +23,7 @@ put working hours matrix and timezone in function, returns UTC working hours mat if timezone begin time_diff = Time.zone.parse(start_time.to_s).in_time_zone(timezone).utc_offset - rescue Exception => e + rescue => e Rails.logger.error "Can't fine tomezone #{timezone}" Rails.logger.error e.inspect Rails.logger.error e.backtrace diff --git a/lib/user_agent.rb b/lib/user_agent.rb index 7c19b126d..ba091cca8 100644 --- a/lib/user_agent.rb +++ b/lib/user_agent.rb @@ -57,7 +57,7 @@ returns begin response = http.request(request) return process(response, uri, count, params, options) - rescue Exception => e + rescue => e return Result.new( error: e.inspect, success: false, @@ -105,7 +105,7 @@ returns begin response = http.request(request) return process(response, uri, count, params, options) - rescue Exception => e + rescue => e return Result.new( error: e.inspect, success: false, @@ -153,7 +153,7 @@ returns begin response = http.request(request) return process(response, uri, count, params, options) - rescue Exception => e + rescue => e return Result.new( error: e.inspect, success: false, @@ -194,7 +194,7 @@ returns begin response = http.request(request) return process(response, uri, count, {}, options) - rescue Exception => e + rescue => e return Result.new( error: e.inspect, success: false,