Skip to content

Commit b0e17e8

Browse files
committed
Don't rescue Exception class (#31387).
Patch by Go MAEDA and Pavel Rosický. git-svn-id: http://svn.redmine.org/redmine/trunk@18197 e93f8b46-1217-0410-a6f0-8f06a7374b81
1 parent a12b7bc commit b0e17e8

28 files changed

+40
-44
lines changed

app/controllers/admin_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def default_configuration
5454
begin
5555
Redmine::DefaultData::Loader::load(params[:lang])
5656
flash[:notice] = l(:notice_default_data_loaded)
57-
rescue Exception => e
57+
rescue => e
5858
flash[:error] = l(:error_can_t_load_default_data, ERB::Util.h(e.message))
5959
end
6060
end
@@ -65,7 +65,7 @@ def test_email
6565
begin
6666
Mailer.deliver_test_email(User.current)
6767
flash[:notice] = l(:notice_email_sent, ERB::Util.h(User.current.mail))
68-
rescue Exception => e
68+
rescue => e
6969
flash[:error] = l(:notice_email_error, ERB::Util.h(Redmine::CodesetUtil.replace_invalid_utf8(e.message.dup)))
7070
end
7171
redirect_to settings_path(:tab => 'notifications')

app/controllers/auth_sources_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_connection
6060
begin
6161
@auth_source.test_connection
6262
flash[:notice] = l(:notice_successful_connection)
63-
rescue Exception => e
63+
rescue => e
6464
flash[:error] = l(:error_unable_to_connect, e.message)
6565
end
6666
redirect_to auth_sources_path

app/controllers/issue_statuses_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def update
7474
def destroy
7575
IssueStatus.find(params[:id]).destroy
7676
redirect_to issue_statuses_path
77-
rescue Exception => e
77+
rescue => e
7878
flash[:error] = l(:error_unable_delete_issue_status, ERB::Util.h(e.message))
7979
redirect_to issue_statuses_path
8080
end

app/models/import.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def set_default_settings
6767
begin
6868
content = File.read(filepath, 256)
6969
separator = [',', ';'].sort_by {|sep| content.count(sep) }.last
70-
rescue Exception => e
70+
rescue => e
7171
end
7272
end
7373
wrapper = '"'
@@ -272,7 +272,7 @@ def remove_file
272272
if file_exists?
273273
begin
274274
File.delete filepath
275-
rescue Exception => e
275+
rescue => e
276276
logger.error "Unable to delete file #{filepath}: #{e.message}" if logger
277277
end
278278
end

app/models/mail_handler.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def self.receive(raw_mail, options={})
5353
# Receives an email and rescues any exception
5454
def self.safe_receive(*args)
5555
receive(*args)
56-
rescue Exception => e
56+
rescue => e
5757
Rails.logger.error "MailHandler: an unexpected error occurred when receiving email: #{e.message}"
5858
return false
5959
end

app/models/mailer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ def self.deliver_mail(mail)
705705
# Log errors when raise_delivery_errors is set to false, Rails does not
706706
mail.raise_delivery_errors = true
707707
super
708-
rescue Exception => e
708+
rescue => e
709709
if ActionMailer::Base.raise_delivery_errors
710710
raise e
711711
else

app/models/query.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def self.visible(*args)
327327
if self == ::Query
328328
# Visibility depends on permissions for each subclass,
329329
# raise an error if the scope is called from Query (eg. Query.visible)
330-
raise Exception.new("Cannot call .visible scope from the base Query class, but from subclasses only.")
330+
raise "Cannot call .visible scope from the base Query class, but from subclasses only."
331331
end
332332

333333
user = args.shift || User.current

app/models/repository.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def self.scm_command
382382
ret = ""
383383
begin
384384
ret = self.scm_adapter_class.client_command if self.scm_adapter_class
385-
rescue Exception => e
385+
rescue => e
386386
logger.error "scm: error during get command: #{e.message}"
387387
end
388388
ret
@@ -392,7 +392,7 @@ def self.scm_version_string
392392
ret = ""
393393
begin
394394
ret = self.scm_adapter_class.client_version_string if self.scm_adapter_class
395-
rescue Exception => e
395+
rescue => e
396396
logger.error "scm: error during get version string: #{e.message}"
397397
end
398398
ret
@@ -402,7 +402,7 @@ def self.scm_available
402402
ret = false
403403
begin
404404
ret = self.scm_adapter_class.client_available if self.scm_adapter_class
405-
rescue Exception => e
405+
rescue => e
406406
logger.error "scm: error during get scm available: #{e.message}"
407407
end
408408
ret

app/models/repository/git.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def tags
8484

8585
def default_branch
8686
scm.default_branch
87-
rescue Exception => e
87+
rescue => e
8888
logger.error "git: error during get default branch: #{e.message}"
8989
nil
9090
end

app/models/tracker.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,6 @@ def self.core_fields(trackers)
142142

143143
private
144144
def check_integrity
145-
raise Exception.new("Cannot delete tracker") if Issue.where(:tracker_id => self.id).any?
145+
raise "Cannot delete tracker" if Issue.where(:tracker_id => self.id).any?
146146
end
147147
end

bin/changelog.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def parse_pagination_items_span_content
133133

134134
begin
135135
raise if items_per_page == 0 || @no_of_issues == 0
136-
rescue Exception => e
136+
rescue => e
137137
puts "No changelog items to process.\n" +
138138
"Make sure to provide a valid version id as the -i parameter."
139139
exit

config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@
357357
if File.exists?(file)
358358
begin
359359
instance_eval File.read(file)
360-
rescue Exception => e
360+
rescue SyntaxError, StandardError => e
361361
puts "An error occurred while loading the routes definition of #{File.basename(plugin_dir)} plugin (#{file}): #{e.message}."
362362
exit 1
363363
end

extra/mail_handler/rdm-mailhandler.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def debug(msg)
204204
def read_key_from_file(filename)
205205
begin
206206
self.key = File.read(filename).strip
207-
rescue Exception => e
207+
rescue => e
208208
$stderr.puts "Unable to read the key from #{filename}:\n#{e.message}"
209209
exit 1
210210
end

extra/svn/reposman.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def self.create(path)
5454
def read_key_from_file(filename)
5555
begin
5656
$api_key = File.read(filename).strip
57-
rescue Exception => e
57+
rescue => e
5858
$stderr.puts "Unable to read the key from #{filename}: #{e.message}"
5959
exit 1
6060
end

lib/redmine/plugin.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def mirror_assets
422422
base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
423423
begin
424424
FileUtils.mkdir_p(base_target_dir)
425-
rescue Exception => e
425+
rescue => e
426426
raise "Could not create directory #{base_target_dir}: " + e.message
427427
end
428428
end
@@ -433,7 +433,7 @@ def mirror_assets
433433
target_dir = File.join(destination, dir.gsub(source, ''))
434434
begin
435435
FileUtils.mkdir_p(target_dir)
436-
rescue Exception => e
436+
rescue => e
437437
raise "Could not create directory #{target_dir}: " + e.message
438438
end
439439
end
@@ -444,7 +444,7 @@ def mirror_assets
444444
unless File.exist?(target) && FileUtils.identical?(file, target)
445445
FileUtils.cp(file, target)
446446
end
447-
rescue Exception => e
447+
rescue => e
448448
raise "Could not copy #{file} to #{target}: " + e.message
449449
end
450450
end

lib/redmine/scm/adapters/abstract_adapter.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,7 @@ def self.shellout(cmd, options = {}, &block)
247247
io.close_write unless options[:write_stdin]
248248
block.call(io) if block_given?
249249
end
250-
## If scm command does not exist,
251-
## Linux JRuby 1.6.2 (ruby-1.8.7-p330) raises java.io.IOException
252-
## in production environment.
253-
# rescue Errno::ENOENT => e
254-
rescue Exception => e
250+
rescue => e
255251
msg = strip_credential(e.message)
256252
# The command failed, log it and re-raise
257253
logmsg = "SCM command failed, "
@@ -282,7 +278,7 @@ def scm_iconv(to, from, str)
282278
str.force_encoding(from)
283279
begin
284280
str.encode(to)
285-
rescue Exception => err
281+
rescue => err
286282
logger.error("failed to convert from #{from} to #{to}. #{err}")
287283
nil
288284
end

lib/redmine/scm/adapters/mercurial_adapter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def info
9292
:lastrev => Revision.new(:revision => tip['revision'],
9393
:scmid => tip['node']))
9494
# rescue HgCommandAborted
95-
rescue Exception => e
95+
rescue => e
9696
logger.error "hg: error during getting info: #{e.message}"
9797
nil
9898
end

lib/redmine/scm/adapters/subversion_adapter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def entries(path=nil, identifier=nil, options={})
115115
})
116116
})
117117
end
118-
rescue Exception => e
118+
rescue => e
119119
logger.error("Error parsing svn output: #{e.message}")
120120
logger.error("Output was:\n #{output}")
121121
end

lib/tasks/email.rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ END_DESC
164164
begin
165165
Mailer.deliver_test_email(user)
166166
puts l(:notice_email_sent, user.mail)
167-
rescue Exception => e
167+
rescue => e
168168
abort l(:notice_email_error, e.message)
169169
end
170170
end

lib/tasks/locales.rake

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ END_DESC
168168
puts "parsing #{filename}..."
169169
begin
170170
parser.parse File.open(filename)
171-
rescue Exception => e1
171+
rescue => e1
172172
puts(e1.message)
173173
puts("")
174174
end
175175
end
176-
rescue Exception => e
176+
rescue => e
177177
puts(e.message)
178178
end
179179
end

lib/tasks/migrate_from_trac.rake

+2-2
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ namespace :redmine do
614614
raise "This directory doesn't exist!" unless File.directory?(path)
615615
raise "#{trac_attachments_directory} doesn't exist!" unless File.directory?(trac_attachments_directory)
616616
@@trac_directory
617-
rescue Exception => e
617+
rescue => e
618618
puts e
619619
return false
620620
end
@@ -629,7 +629,7 @@ namespace :redmine do
629629
# If adapter is sqlite or sqlite3, make sure that trac.db exists
630630
raise "#{trac_db_path} doesn't exist!" if %w(sqlite3).include?(adapter) && !File.exist?(trac_db_path)
631631
@@trac_adapter = adapter
632-
rescue Exception => e
632+
rescue => e
633633
puts e
634634
return false
635635
end

test/functional/admin_controller_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_load_default_configuration_data
7575

7676
def test_load_default_configuration_data_should_rescue_error
7777
delete_configuration_data
78-
Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong"))
78+
Redmine::DefaultData::Loader.stubs(:load).raises(StandardError.new("Something went wrong"))
7979
post :default_configuration, :params => {
8080
:lang => 'fr'
8181
}
@@ -99,7 +99,7 @@ def test_test_email
9999
end
100100

101101
def test_test_email_failure_should_display_the_error
102-
Mailer.stubs(:test_email).raises(Exception, 'Some error message')
102+
Mailer.stubs(:test_email).raises(StandardError, 'Some error message')
103103
post :test_email
104104
assert_redirected_to '/settings?tab=notifications'
105105
assert_match /Some error message/, flash[:error]

test/test_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def with_locale(locale, &block)
121121
def self.ldap_configured?
122122
@test_ldap = Net::LDAP.new(:host => $redmine_test_ldap_server, :port => 389)
123123
return @test_ldap.bind
124-
rescue Exception => e
124+
rescue => e
125125
# LDAP is not listening
126126
return nil
127127
end

test/unit/issue_nested_set_concurrency_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def threaded(count, &block)
8484
ActiveRecord::Base.connection_pool.with_connection do
8585
begin
8686
yield
87-
rescue Exception => e
87+
rescue => e
8888
Thread.current[:exception] = e.message
8989
end
9090
end

test/unit/mail_handler_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ def test_extract_options_from_env_should_return_options
12231223
end
12241224

12251225
def test_safe_receive_should_rescue_exceptions_and_return_false
1226-
MailHandler.stubs(:receive).raises(Exception.new "Something went wrong")
1226+
MailHandler.stubs(:receive).raises(StandardError.new "Something went wrong")
12271227

12281228
assert_equal false, MailHandler.safe_receive
12291229
end

test/unit/mailer_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,10 @@ def test_should_escape_html_templates_only
920920

921921
def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true
922922
mail = Mailer.test_email(User.find(1))
923-
mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
923+
mail.delivery_method.stubs(:deliver!).raises(StandardError.new("delivery error"))
924924

925925
ActionMailer::Base.raise_delivery_errors = true
926-
assert_raise Exception, "delivery error" do
926+
assert_raise StandardError, "delivery error" do
927927
mail.deliver
928928
end
929929
ensure
@@ -932,7 +932,7 @@ def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true
932932

933933
def test_should_log_delivery_errors_when_raise_delivery_errors_is_false
934934
mail = Mailer.test_email(User.find(1))
935-
mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
935+
mail.delivery_method.stubs(:deliver!).raises(StandardError.new("delivery error"))
936936

937937
Rails.logger.expects(:error).with("Email delivery error: delivery error")
938938
ActionMailer::Base.raise_delivery_errors = false

test/unit/project_nested_set_concurrency_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_concurrency
5252
c2.reload.destroy
5353
c1.reload.destroy
5454
end
55-
rescue Exception => e
55+
rescue => e
5656
Thread.current[:exception] = e.message
5757
end
5858
end

test/unit/tracker_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_destroying_a_tracker_with_issues_should_raise_an_error
129129
tracker = Tracker.find(1)
130130

131131
assert_no_difference 'Tracker.count' do
132-
assert_raise Exception do
132+
assert_raise StandardError do
133133
tracker.destroy
134134
end
135135
end

0 commit comments

Comments
 (0)