Corrected with rubocop cop 'Lint/RescueException'.

This commit is contained in:
Thorsten Eckel 2015-05-08 16:09:24 +02:00
parent 6decb755f5
commit b6c2b6750a
17 changed files with 30 additions and 32 deletions

View file

@ -193,7 +193,5 @@ Style/Documentation:
Description: 'Document classes and non-namespace modules.' Description: 'Document classes and non-namespace modules.'
Enabled: false Enabled: false
Lint/RescueException:
Enabled: false
Lint/UselessAssignment: Lint/UselessAssignment:
Enabled: false Enabled: false

View file

@ -287,7 +287,7 @@ class ApplicationController < ActionController::Base
generic_object.param_set_associations( params ) generic_object.param_set_associations( params )
model_create_render_item(generic_object) model_create_render_item(generic_object)
rescue Exception => e rescue => e
logger.error e.message logger.error e.message
logger.error e.backtrace.inspect logger.error e.backtrace.inspect
render json: { error: e.message }, status: :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
@ -309,7 +309,7 @@ class ApplicationController < ActionController::Base
generic_object.param_set_associations( params ) generic_object.param_set_associations( params )
model_update_render_item( generic_object ) model_update_render_item( generic_object )
rescue Exception => e rescue => e
logger.error e.message logger.error e.message
logger.error e.backtrace.inspect logger.error e.backtrace.inspect
render json: { error: e.message }, status: :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
@ -323,7 +323,7 @@ class ApplicationController < ActionController::Base
generic_object = object.find( params[:id] ) generic_object = object.find( params[:id] )
generic_object.destroy generic_object.destroy
model_destory_render_item() model_destory_render_item()
rescue Exception => e rescue => e
logger.error e.message logger.error e.message
logger.error e.backtrace.inspect logger.error e.backtrace.inspect
render json: { error: e.message }, status: :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
@ -343,7 +343,7 @@ class ApplicationController < ActionController::Base
generic_object = object.find( params[:id] ) generic_object = object.find( params[:id] )
model_show_render_item(generic_object) model_show_render_item(generic_object)
rescue Exception => e rescue => e
logger.error e.message logger.error e.message
logger.error e.backtrace.inspect logger.error e.backtrace.inspect
render json: { error: e.message }, status: :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
@ -356,7 +356,7 @@ class ApplicationController < ActionController::Base
def model_index_render (object, _params) def model_index_render (object, _params)
generic_objects = object.all generic_objects = object.all
model_index_render_result( generic_objects ) model_index_render_result( generic_objects )
rescue Exception => e rescue => e
logger.error e.message logger.error e.message
logger.error e.backtrace.inspect logger.error e.backtrace.inspect
render json: { error: e.message }, status: :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity

View file

@ -628,7 +628,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
else else
found = Channel::POP3.new.fetch( { options: params[:inbound][:options] }, 'verify', subject ) found = Channel::POP3.new.fetch( { options: params[:inbound][:options] }, 'verify', subject )
end end
rescue Exception => e rescue => e
render json: { render json: {
result: 'invalid', result: 'invalid',
message: e.to_s, message: e.to_s,
@ -762,7 +762,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
options: params[:options] options: params[:options]
} }
) )
rescue Exception => e rescue => e
# check if sending email was ok, but mailserver rejected # check if sending email was ok, but mailserver rejected
if !subject if !subject
@ -806,7 +806,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
mail, mail,
nil nil
) )
rescue Exception => e rescue => e
message_human = '' message_human = ''
translation_map.each {|key, message| translation_map.each {|key, message|
if e.message =~ /#{Regexp.escape(key)}/i if e.message =~ /#{Regexp.escape(key)}/i
@ -846,7 +846,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
begin begin
Channel::IMAP.new.fetch( { options: params[:options] }, 'check' ) Channel::IMAP.new.fetch( { options: params[:options] }, 'check' )
rescue Exception => e rescue => e
message_human = '' message_human = ''
translation_map.each {|key, message| translation_map.each {|key, message|
if e.message =~ /#{Regexp.escape(key)}/i if e.message =~ /#{Regexp.escape(key)}/i
@ -869,7 +869,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
begin begin
Channel::POP3.new.fetch( { options: params[:options] }, 'check' ) Channel::POP3.new.fetch( { options: params[:options] }, 'check' )
rescue Exception => e rescue => e
message_human = '' message_human = ''
translation_map.each {|key, message| translation_map.each {|key, message|
if e.message =~ /#{Regexp.escape(key)}/i 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 = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
ress.map { |r| [r.exchange.to_s, IPSocket.getaddress(r.exchange.to_s), r.preference] } ress.map { |r| [r.exchange.to_s, IPSocket.getaddress(r.exchange.to_s), r.preference] }
end end
rescue Exception => e rescue => e
logger.error e.message logger.error e.message
logger.error e.backtrace.inspect logger.error e.backtrace.inspect
end end

View file

@ -137,7 +137,7 @@ class LongPollingController < ApplicationController
return return
end end
end end
rescue Exception => e rescue => e
logger.error e.inspect logger.error e.inspect
logger.error e.backtrace logger.error e.backtrace
render json: { error: 'Invalid client_id in receive loop!' }, status: :unprocessable_entity render json: { error: 'Invalid client_id in receive loop!' }, status: :unprocessable_entity

View file

@ -176,7 +176,7 @@ class UsersController < ApplicationController
user_new = User.find( user.id ) user_new = User.find( user.id )
render json: user_new, status: :created render json: user_new, status: :created
rescue Exception => e rescue => e
render json: { error: e.message }, status: :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
end end
end end
@ -220,7 +220,7 @@ class UsersController < ApplicationController
# get new data # get new data
user_new = User.find( params[:id] ) user_new = User.find( params[:id] )
render json: user_new, status: :ok render json: user_new, status: :ok
rescue Exception => e rescue => e
render json: { error: e.message }, status: :unprocessable_entity render json: { error: e.message }, status: :unprocessable_entity
end end
end end

View file

@ -9,7 +9,7 @@ class Channel < ApplicationModel
begin begin
c = eval 'Channel::' + channel[:adapter].upcase + '.new' # rubocop:disable Lint/Eval c = eval 'Channel::' + channel[:adapter].upcase + '.new' # rubocop:disable Lint/Eval
c.fetch(channel) c.fetch(channel)
rescue Exception => e rescue => e
logger.error "can't use " + 'Channel::' + channel[:adapter].upcase logger.error "can't use " + 'Channel::' + channel[:adapter].upcase
logger.error e.inspect logger.error e.inspect
logger.error e.backtrace logger.error e.backtrace

View file

@ -338,7 +338,7 @@ class Channel::EmailParser
filters.each {|_prio, backend| filters.each {|_prio, backend|
begin begin
backend.run( channel, mail ) backend.run( channel, mail )
rescue Exception => e rescue => e
Rails.logger.error "can't run postmaster pre filter #{backend}" Rails.logger.error "can't run postmaster pre filter #{backend}"
Rails.logger.error e.inspect Rails.logger.error e.inspect
return false return false
@ -487,7 +487,7 @@ class Channel::EmailParser
filters.each {|_prio, backend| filters.each {|_prio, backend|
begin begin
backend.run( channel, mail, ticket, article, user ) 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 "can't run postmaster post filter #{backend}"
Rails.logger.error e.inspect Rails.logger.error e.inspect
end end

View file

@ -8,7 +8,7 @@ module Channel::EmailSend
begin begin
c = eval 'Channel::' + channel[:adapter] + '.new' # rubocop:disable Lint/Eval c = eval 'Channel::' + channel[:adapter] + '.new' # rubocop:disable Lint/Eval
c.send(attr, channel, notification) c.send(attr, channel, notification)
rescue Exception => e rescue => e
Rails.logger.error "can't use " + 'Channel::' + channel[:adapter] Rails.logger.error "can't use " + 'Channel::' + channel[:adapter]
Rails.logger.error e.inspect Rails.logger.error e.inspect
Rails.logger.error e.backtrace Rails.logger.error e.backtrace

View file

@ -25,7 +25,7 @@ module Channel::Filter::Database
Rails.logger.info " is not matching #{ key.downcase }:'#{ mail[ key.downcase.to_sym ] }' on #{value}" Rails.logger.info " is not matching #{ key.downcase }:'#{ mail[ key.downcase.to_sym ] }' on #{value}"
match = false match = false
end end
rescue Exception => e rescue => e
match = false match = false
Rails.logger.error "can't use match rule #{value} on #{mail[ key.to_sym ]}" Rails.logger.error "can't use match rule #{value} on #{mail[ key.to_sym ]}"
Rails.logger.error e.inspect Rails.logger.error e.inspect

View file

@ -29,7 +29,7 @@ class Channel::IMAP < Channel::EmailParser
# try LOGIN, if not - try plain # try LOGIN, if not - try plain
begin begin
@imap.authenticate( 'LOGIN', channel[:options][:user], channel[:options][:password] ) @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 if e.to_s !~ /(unsupported\s(authenticate|authentication)\smechanism|not\ssupported)/i
raise e raise e
end end

View file

@ -112,7 +112,7 @@ class Channel::TWITTER2
elsif tweet.respond_to?('from_user_id') elsif tweet.respond_to?('from_user_id')
begin begin
sender = @client.user(tweet.from_user_id) sender = @client.user(tweet.from_user_id)
rescue Exception => e rescue => e
Rails.logger.error 'Exception: twitter: ' + e.inspect Rails.logger.error 'Exception: twitter: ' + e.inspect
return return
end end

View file

@ -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}" Rails.logger.info "Can't bind to '#{config[:host]}', #{ldap.get_operation_result.code}, #{ldap.get_operation_result.message}"
return return
end end
rescue Exception => e rescue => e
Rails.logger.info "Can't connect to '#{config[:host]}', #{e}" Rails.logger.info "Can't connect to '#{config[:host]}', #{e}"
return return
end end

View file

@ -32,7 +32,7 @@ write a cache
end end
begin begin
Rails.cache.write( key.to_s, data, params) Rails.cache.write( key.to_s, data, params)
rescue Exception => e rescue => e
Rails.logger.error "NOTICE: #{e.message}" Rails.logger.error "NOTICE: #{e.message}"
end end
end end

View file

@ -27,7 +27,7 @@ module Rss
break item if fetched == limit.to_i break item if fetched == limit.to_i
} }
Cache.write( cache_key, items, expires_in: 4.hours ) Cache.write( cache_key, items, expires_in: 4.hours )
rescue Exception => e rescue => e
Rails.logger.error "can't fetch #{url}" Rails.logger.error "can't fetch #{url}"
Rails.logger.error e.inspect Rails.logger.error e.inspect
return return

View file

@ -266,7 +266,7 @@ returns
data[:user] = data_json['user'] # for compat. reasons data[:user] = data_json['user'] # for compat. reasons
end end
} }
rescue Exception => e rescue => e
Rails.logger.error e.inspect Rails.logger.error e.inspect
destory(client_id) destory(client_id)
Rails.logger.error "ERROR: reading session file '#{session_file}', remove session." Rails.logger.error "ERROR: reading session file '#{session_file}', remove session."

View file

@ -23,7 +23,7 @@ put working hours matrix and timezone in function, returns UTC working hours mat
if timezone if timezone
begin begin
time_diff = Time.zone.parse(start_time.to_s).in_time_zone(timezone).utc_offset 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 "Can't fine tomezone #{timezone}"
Rails.logger.error e.inspect Rails.logger.error e.inspect
Rails.logger.error e.backtrace Rails.logger.error e.backtrace

View file

@ -57,7 +57,7 @@ returns
begin begin
response = http.request(request) response = http.request(request)
return process(response, uri, count, params, options) return process(response, uri, count, params, options)
rescue Exception => e rescue => e
return Result.new( return Result.new(
error: e.inspect, error: e.inspect,
success: false, success: false,
@ -105,7 +105,7 @@ returns
begin begin
response = http.request(request) response = http.request(request)
return process(response, uri, count, params, options) return process(response, uri, count, params, options)
rescue Exception => e rescue => e
return Result.new( return Result.new(
error: e.inspect, error: e.inspect,
success: false, success: false,
@ -153,7 +153,7 @@ returns
begin begin
response = http.request(request) response = http.request(request)
return process(response, uri, count, params, options) return process(response, uri, count, params, options)
rescue Exception => e rescue => e
return Result.new( return Result.new(
error: e.inspect, error: e.inspect,
success: false, success: false,
@ -194,7 +194,7 @@ returns
begin begin
response = http.request(request) response = http.request(request)
return process(response, uri, count, {}, options) return process(response, uri, count, {}, options)
rescue Exception => e rescue => e
return Result.new( return Result.new(
error: e.inspect, error: e.inspect,
success: false, success: false,