summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-05-25 06:50:25 +0000
committerGo MAEDA <maeda@farend.jp>2019-05-25 06:50:25 +0000
commitb0e17e8199bb40d0b1bed2c3dded355f439d8b3a (patch)
tree694b9ccde636af70a5aa515b62d1020a5eac9e62
parenta12b7bcf2931045e63093adcd765d7c6e022fa05 (diff)
downloadredmine-b0e17e8199bb40d0b1bed2c3dded355f439d8b3a.tar.gz
redmine-b0e17e8199bb40d0b1bed2c3dded355f439d8b3a.zip
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
-rw-r--r--app/controllers/admin_controller.rb4
-rw-r--r--app/controllers/auth_sources_controller.rb2
-rw-r--r--app/controllers/issue_statuses_controller.rb2
-rw-r--r--app/models/import.rb4
-rwxr-xr-xapp/models/mail_handler.rb2
-rw-r--r--app/models/mailer.rb2
-rw-r--r--app/models/query.rb2
-rw-r--r--app/models/repository.rb6
-rw-r--r--app/models/repository/git.rb2
-rw-r--r--app/models/tracker.rb2
-rw-r--r--bin/changelog.rb2
-rw-r--r--config/routes.rb2
-rw-r--r--extra/mail_handler/rdm-mailhandler.rb2
-rwxr-xr-xextra/svn/reposman.rb2
-rw-r--r--lib/redmine/plugin.rb6
-rw-r--r--lib/redmine/scm/adapters/abstract_adapter.rb8
-rw-r--r--lib/redmine/scm/adapters/mercurial_adapter.rb2
-rw-r--r--lib/redmine/scm/adapters/subversion_adapter.rb2
-rw-r--r--lib/tasks/email.rake2
-rw-r--r--lib/tasks/locales.rake4
-rw-r--r--lib/tasks/migrate_from_trac.rake4
-rw-r--r--test/functional/admin_controller_test.rb4
-rw-r--r--test/test_helper.rb2
-rw-r--r--test/unit/issue_nested_set_concurrency_test.rb2
-rw-r--r--test/unit/mail_handler_test.rb2
-rw-r--r--test/unit/mailer_test.rb6
-rw-r--r--test/unit/project_nested_set_concurrency_test.rb2
-rw-r--r--test/unit/tracker_test.rb2
28 files changed, 40 insertions, 44 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index eb2288eff..0a0a87eab 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -54,7 +54,7 @@ class AdminController < ApplicationController
begin
Redmine::DefaultData::Loader::load(params[:lang])
flash[:notice] = l(:notice_default_data_loaded)
- rescue Exception => e
+ rescue => e
flash[:error] = l(:error_can_t_load_default_data, ERB::Util.h(e.message))
end
end
@@ -65,7 +65,7 @@ class AdminController < ApplicationController
begin
Mailer.deliver_test_email(User.current)
flash[:notice] = l(:notice_email_sent, ERB::Util.h(User.current.mail))
- rescue Exception => e
+ rescue => e
flash[:error] = l(:notice_email_error, ERB::Util.h(Redmine::CodesetUtil.replace_invalid_utf8(e.message.dup)))
end
redirect_to settings_path(:tab => 'notifications')
diff --git a/app/controllers/auth_sources_controller.rb b/app/controllers/auth_sources_controller.rb
index 8eaa155e4..c746f339b 100644
--- a/app/controllers/auth_sources_controller.rb
+++ b/app/controllers/auth_sources_controller.rb
@@ -60,7 +60,7 @@ class AuthSourcesController < ApplicationController
begin
@auth_source.test_connection
flash[:notice] = l(:notice_successful_connection)
- rescue Exception => e
+ rescue => e
flash[:error] = l(:error_unable_to_connect, e.message)
end
redirect_to auth_sources_path
diff --git a/app/controllers/issue_statuses_controller.rb b/app/controllers/issue_statuses_controller.rb
index 2bc6e43de..2e5f66017 100644
--- a/app/controllers/issue_statuses_controller.rb
+++ b/app/controllers/issue_statuses_controller.rb
@@ -74,7 +74,7 @@ class IssueStatusesController < ApplicationController
def destroy
IssueStatus.find(params[:id]).destroy
redirect_to issue_statuses_path
- rescue Exception => e
+ rescue => e
flash[:error] = l(:error_unable_delete_issue_status, ERB::Util.h(e.message))
redirect_to issue_statuses_path
end
diff --git a/app/models/import.rb b/app/models/import.rb
index ef4b0321e..721e812bd 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -67,7 +67,7 @@ class Import < ActiveRecord::Base
begin
content = File.read(filepath, 256)
separator = [',', ';'].sort_by {|sep| content.count(sep) }.last
- rescue Exception => e
+ rescue => e
end
end
wrapper = '"'
@@ -272,7 +272,7 @@ class Import < ActiveRecord::Base
if file_exists?
begin
File.delete filepath
- rescue Exception => e
+ rescue => e
logger.error "Unable to delete file #{filepath}: #{e.message}" if logger
end
end
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 8b5d7133f..ef7ef429d 100755
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -53,7 +53,7 @@ class MailHandler < ActionMailer::Base
# Receives an email and rescues any exception
def self.safe_receive(*args)
receive(*args)
- rescue Exception => e
+ rescue => e
Rails.logger.error "MailHandler: an unexpected error occurred when receiving email: #{e.message}"
return false
end
diff --git a/app/models/mailer.rb b/app/models/mailer.rb
index c0a30d35a..8ab43e9b6 100644
--- a/app/models/mailer.rb
+++ b/app/models/mailer.rb
@@ -705,7 +705,7 @@ class Mailer < ActionMailer::Base
# Log errors when raise_delivery_errors is set to false, Rails does not
mail.raise_delivery_errors = true
super
- rescue Exception => e
+ rescue => e
if ActionMailer::Base.raise_delivery_errors
raise e
else
diff --git a/app/models/query.rb b/app/models/query.rb
index 6dea88c78..f5f929b30 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -327,7 +327,7 @@ class Query < ActiveRecord::Base
if self == ::Query
# Visibility depends on permissions for each subclass,
# raise an error if the scope is called from Query (eg. Query.visible)
- raise Exception.new("Cannot call .visible scope from the base Query class, but from subclasses only.")
+ raise "Cannot call .visible scope from the base Query class, but from subclasses only."
end
user = args.shift || User.current
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 0284e1b29..7da99faa3 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -382,7 +382,7 @@ class Repository < ActiveRecord::Base
ret = ""
begin
ret = self.scm_adapter_class.client_command if self.scm_adapter_class
- rescue Exception => e
+ rescue => e
logger.error "scm: error during get command: #{e.message}"
end
ret
@@ -392,7 +392,7 @@ class Repository < ActiveRecord::Base
ret = ""
begin
ret = self.scm_adapter_class.client_version_string if self.scm_adapter_class
- rescue Exception => e
+ rescue => e
logger.error "scm: error during get version string: #{e.message}"
end
ret
@@ -402,7 +402,7 @@ class Repository < ActiveRecord::Base
ret = false
begin
ret = self.scm_adapter_class.client_available if self.scm_adapter_class
- rescue Exception => e
+ rescue => e
logger.error "scm: error during get scm available: #{e.message}"
end
ret
diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb
index a8c5efd33..6cff4507d 100644
--- a/app/models/repository/git.rb
+++ b/app/models/repository/git.rb
@@ -84,7 +84,7 @@ class Repository::Git < Repository
def default_branch
scm.default_branch
- rescue Exception => e
+ rescue => e
logger.error "git: error during get default branch: #{e.message}"
nil
end
diff --git a/app/models/tracker.rb b/app/models/tracker.rb
index 088ad3948..aeb86ca9e 100644
--- a/app/models/tracker.rb
+++ b/app/models/tracker.rb
@@ -142,6 +142,6 @@ class Tracker < ActiveRecord::Base
private
def check_integrity
- raise Exception.new("Cannot delete tracker") if Issue.where(:tracker_id => self.id).any?
+ raise "Cannot delete tracker" if Issue.where(:tracker_id => self.id).any?
end
end
diff --git a/bin/changelog.rb b/bin/changelog.rb
index 7862f21eb..2e17f2283 100644
--- a/bin/changelog.rb
+++ b/bin/changelog.rb
@@ -133,7 +133,7 @@ module Redmine
begin
raise if items_per_page == 0 || @no_of_issues == 0
- rescue Exception => e
+ rescue => e
puts "No changelog items to process.\n" +
"Make sure to provide a valid version id as the -i parameter."
exit
diff --git a/config/routes.rb b/config/routes.rb
index 74257d3ea..3028ec192 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -357,7 +357,7 @@ Rails.application.routes.draw do
if File.exists?(file)
begin
instance_eval File.read(file)
- rescue Exception => e
+ rescue SyntaxError, StandardError => e
puts "An error occurred while loading the routes definition of #{File.basename(plugin_dir)} plugin (#{file}): #{e.message}."
exit 1
end
diff --git a/extra/mail_handler/rdm-mailhandler.rb b/extra/mail_handler/rdm-mailhandler.rb
index e0053fde3..b82532c48 100644
--- a/extra/mail_handler/rdm-mailhandler.rb
+++ b/extra/mail_handler/rdm-mailhandler.rb
@@ -204,7 +204,7 @@ END_DESC
def read_key_from_file(filename)
begin
self.key = File.read(filename).strip
- rescue Exception => e
+ rescue => e
$stderr.puts "Unable to read the key from #{filename}:\n#{e.message}"
exit 1
end
diff --git a/extra/svn/reposman.rb b/extra/svn/reposman.rb
index c058b5cf4..28c7d257a 100755
--- a/extra/svn/reposman.rb
+++ b/extra/svn/reposman.rb
@@ -54,7 +54,7 @@ end
def read_key_from_file(filename)
begin
$api_key = File.read(filename).strip
- rescue Exception => e
+ rescue => e
$stderr.puts "Unable to read the key from #{filename}: #{e.message}"
exit 1
end
diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb
index b5fa3d209..998595339 100644
--- a/lib/redmine/plugin.rb
+++ b/lib/redmine/plugin.rb
@@ -422,7 +422,7 @@ module Redmine
base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
begin
FileUtils.mkdir_p(base_target_dir)
- rescue Exception => e
+ rescue => e
raise "Could not create directory #{base_target_dir}: " + e.message
end
end
@@ -433,7 +433,7 @@ module Redmine
target_dir = File.join(destination, dir.gsub(source, ''))
begin
FileUtils.mkdir_p(target_dir)
- rescue Exception => e
+ rescue => e
raise "Could not create directory #{target_dir}: " + e.message
end
end
@@ -444,7 +444,7 @@ module Redmine
unless File.exist?(target) && FileUtils.identical?(file, target)
FileUtils.cp(file, target)
end
- rescue Exception => e
+ rescue => e
raise "Could not copy #{file} to #{target}: " + e.message
end
end
diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb
index d66f0da25..694273a71 100644
--- a/lib/redmine/scm/adapters/abstract_adapter.rb
+++ b/lib/redmine/scm/adapters/abstract_adapter.rb
@@ -247,11 +247,7 @@ module Redmine
io.close_write unless options[:write_stdin]
block.call(io) if block_given?
end
- ## If scm command does not exist,
- ## Linux JRuby 1.6.2 (ruby-1.8.7-p330) raises java.io.IOException
- ## in production environment.
- # rescue Errno::ENOENT => e
- rescue Exception => e
+ rescue => e
msg = strip_credential(e.message)
# The command failed, log it and re-raise
logmsg = "SCM command failed, "
@@ -282,7 +278,7 @@ module Redmine
str.force_encoding(from)
begin
str.encode(to)
- rescue Exception => err
+ rescue => err
logger.error("failed to convert from #{from} to #{to}. #{err}")
nil
end
diff --git a/lib/redmine/scm/adapters/mercurial_adapter.rb b/lib/redmine/scm/adapters/mercurial_adapter.rb
index d5a87f2b3..f882b08cb 100644
--- a/lib/redmine/scm/adapters/mercurial_adapter.rb
+++ b/lib/redmine/scm/adapters/mercurial_adapter.rb
@@ -92,7 +92,7 @@ module Redmine
:lastrev => Revision.new(:revision => tip['revision'],
:scmid => tip['node']))
# rescue HgCommandAborted
- rescue Exception => e
+ rescue => e
logger.error "hg: error during getting info: #{e.message}"
nil
end
diff --git a/lib/redmine/scm/adapters/subversion_adapter.rb b/lib/redmine/scm/adapters/subversion_adapter.rb
index 5ee7159c0..ad4d7c281 100644
--- a/lib/redmine/scm/adapters/subversion_adapter.rb
+++ b/lib/redmine/scm/adapters/subversion_adapter.rb
@@ -115,7 +115,7 @@ module Redmine
})
})
end
- rescue Exception => e
+ rescue => e
logger.error("Error parsing svn output: #{e.message}")
logger.error("Output was:\n #{output}")
end
diff --git a/lib/tasks/email.rake b/lib/tasks/email.rake
index 25d7d667b..0b0b2b752 100644
--- a/lib/tasks/email.rake
+++ b/lib/tasks/email.rake
@@ -164,7 +164,7 @@ END_DESC
begin
Mailer.deliver_test_email(user)
puts l(:notice_email_sent, user.mail)
- rescue Exception => e
+ rescue => e
abort l(:notice_email_error, e.message)
end
end
diff --git a/lib/tasks/locales.rake b/lib/tasks/locales.rake
index 028a25154..952f8f6de 100644
--- a/lib/tasks/locales.rake
+++ b/lib/tasks/locales.rake
@@ -168,12 +168,12 @@ END_DESC
puts "parsing #{filename}..."
begin
parser.parse File.open(filename)
- rescue Exception => e1
+ rescue => e1
puts(e1.message)
puts("")
end
end
- rescue Exception => e
+ rescue => e
puts(e.message)
end
end
diff --git a/lib/tasks/migrate_from_trac.rake b/lib/tasks/migrate_from_trac.rake
index eb0d81e0a..8bf31c3d3 100644
--- a/lib/tasks/migrate_from_trac.rake
+++ b/lib/tasks/migrate_from_trac.rake
@@ -614,7 +614,7 @@ namespace :redmine do
raise "This directory doesn't exist!" unless File.directory?(path)
raise "#{trac_attachments_directory} doesn't exist!" unless File.directory?(trac_attachments_directory)
@@trac_directory
- rescue Exception => e
+ rescue => e
puts e
return false
end
@@ -629,7 +629,7 @@ namespace :redmine do
# If adapter is sqlite or sqlite3, make sure that trac.db exists
raise "#{trac_db_path} doesn't exist!" if %w(sqlite3).include?(adapter) && !File.exist?(trac_db_path)
@@trac_adapter = adapter
- rescue Exception => e
+ rescue => e
puts e
return false
end
diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb
index 6d951f68f..e2bc2f9f0 100644
--- a/test/functional/admin_controller_test.rb
+++ b/test/functional/admin_controller_test.rb
@@ -75,7 +75,7 @@ class AdminControllerTest < Redmine::ControllerTest
def test_load_default_configuration_data_should_rescue_error
delete_configuration_data
- Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong"))
+ Redmine::DefaultData::Loader.stubs(:load).raises(StandardError.new("Something went wrong"))
post :default_configuration, :params => {
:lang => 'fr'
}
@@ -99,7 +99,7 @@ class AdminControllerTest < Redmine::ControllerTest
end
def test_test_email_failure_should_display_the_error
- Mailer.stubs(:test_email).raises(Exception, 'Some error message')
+ Mailer.stubs(:test_email).raises(StandardError, 'Some error message')
post :test_email
assert_redirected_to '/settings?tab=notifications'
assert_match /Some error message/, flash[:error]
diff --git a/test/test_helper.rb b/test/test_helper.rb
index c9f6320bc..868f6badf 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -121,7 +121,7 @@ class ActiveSupport::TestCase
def self.ldap_configured?
@test_ldap = Net::LDAP.new(:host => $redmine_test_ldap_server, :port => 389)
return @test_ldap.bind
- rescue Exception => e
+ rescue => e
# LDAP is not listening
return nil
end
diff --git a/test/unit/issue_nested_set_concurrency_test.rb b/test/unit/issue_nested_set_concurrency_test.rb
index 0a1c38bba..c31aae5b8 100644
--- a/test/unit/issue_nested_set_concurrency_test.rb
+++ b/test/unit/issue_nested_set_concurrency_test.rb
@@ -84,7 +84,7 @@ class IssueNestedSetConcurrencyTest < ActiveSupport::TestCase
ActiveRecord::Base.connection_pool.with_connection do
begin
yield
- rescue Exception => e
+ rescue => e
Thread.current[:exception] = e.message
end
end
diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb
index 61b60434f..40de6bbbc 100644
--- a/test/unit/mail_handler_test.rb
+++ b/test/unit/mail_handler_test.rb
@@ -1223,7 +1223,7 @@ class MailHandlerTest < ActiveSupport::TestCase
end
def test_safe_receive_should_rescue_exceptions_and_return_false
- MailHandler.stubs(:receive).raises(Exception.new "Something went wrong")
+ MailHandler.stubs(:receive).raises(StandardError.new "Something went wrong")
assert_equal false, MailHandler.safe_receive
end
diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb
index 75890baf3..ad04fbb90 100644
--- a/test/unit/mailer_test.rb
+++ b/test/unit/mailer_test.rb
@@ -920,10 +920,10 @@ class MailerTest < ActiveSupport::TestCase
def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true
mail = Mailer.test_email(User.find(1))
- mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
+ mail.delivery_method.stubs(:deliver!).raises(StandardError.new("delivery error"))
ActionMailer::Base.raise_delivery_errors = true
- assert_raise Exception, "delivery error" do
+ assert_raise StandardError, "delivery error" do
mail.deliver
end
ensure
@@ -932,7 +932,7 @@ class MailerTest < ActiveSupport::TestCase
def test_should_log_delivery_errors_when_raise_delivery_errors_is_false
mail = Mailer.test_email(User.find(1))
- mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
+ mail.delivery_method.stubs(:deliver!).raises(StandardError.new("delivery error"))
Rails.logger.expects(:error).with("Email delivery error: delivery error")
ActionMailer::Base.raise_delivery_errors = false
diff --git a/test/unit/project_nested_set_concurrency_test.rb b/test/unit/project_nested_set_concurrency_test.rb
index 715faed0c..dbf936a75 100644
--- a/test/unit/project_nested_set_concurrency_test.rb
+++ b/test/unit/project_nested_set_concurrency_test.rb
@@ -52,7 +52,7 @@ class ProjectNestedSetConcurrencyTest < ActiveSupport::TestCase
c2.reload.destroy
c1.reload.destroy
end
- rescue Exception => e
+ rescue => e
Thread.current[:exception] = e.message
end
end
diff --git a/test/unit/tracker_test.rb b/test/unit/tracker_test.rb
index 4cace7e3b..62ac35afb 100644
--- a/test/unit/tracker_test.rb
+++ b/test/unit/tracker_test.rb
@@ -129,7 +129,7 @@ class TrackerTest < ActiveSupport::TestCase
tracker = Tracker.find(1)
assert_no_difference 'Tracker.count' do
- assert_raise Exception do
+ assert_raise StandardError do
tracker.destroy
end
end