Patch by Go MAEDA and Pavel Rosický. git-svn-id: http://svn.redmine.org/redmine/trunk@18197 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/4.1.0
begin | begin | ||||
Redmine::DefaultData::Loader::load(params[:lang]) | Redmine::DefaultData::Loader::load(params[:lang]) | ||||
flash[:notice] = l(:notice_default_data_loaded) | 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)) | flash[:error] = l(:error_can_t_load_default_data, ERB::Util.h(e.message)) | ||||
end | end | ||||
end | end | ||||
begin | begin | ||||
Mailer.deliver_test_email(User.current) | Mailer.deliver_test_email(User.current) | ||||
flash[:notice] = l(:notice_email_sent, ERB::Util.h(User.current.mail)) | 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))) | flash[:error] = l(:notice_email_error, ERB::Util.h(Redmine::CodesetUtil.replace_invalid_utf8(e.message.dup))) | ||||
end | end | ||||
redirect_to settings_path(:tab => 'notifications') | redirect_to settings_path(:tab => 'notifications') |
begin | begin | ||||
@auth_source.test_connection | @auth_source.test_connection | ||||
flash[:notice] = l(:notice_successful_connection) | flash[:notice] = l(:notice_successful_connection) | ||||
rescue Exception => e | |||||
rescue => e | |||||
flash[:error] = l(:error_unable_to_connect, e.message) | flash[:error] = l(:error_unable_to_connect, e.message) | ||||
end | end | ||||
redirect_to auth_sources_path | redirect_to auth_sources_path |
def destroy | def destroy | ||||
IssueStatus.find(params[:id]).destroy | IssueStatus.find(params[:id]).destroy | ||||
redirect_to issue_statuses_path | redirect_to issue_statuses_path | ||||
rescue Exception => e | |||||
rescue => e | |||||
flash[:error] = l(:error_unable_delete_issue_status, ERB::Util.h(e.message)) | flash[:error] = l(:error_unable_delete_issue_status, ERB::Util.h(e.message)) | ||||
redirect_to issue_statuses_path | redirect_to issue_statuses_path | ||||
end | end |
begin | begin | ||||
content = File.read(filepath, 256) | content = File.read(filepath, 256) | ||||
separator = [',', ';'].sort_by {|sep| content.count(sep) }.last | separator = [',', ';'].sort_by {|sep| content.count(sep) }.last | ||||
rescue Exception => e | |||||
rescue => e | |||||
end | end | ||||
end | end | ||||
wrapper = '"' | wrapper = '"' | ||||
if file_exists? | if file_exists? | ||||
begin | begin | ||||
File.delete filepath | File.delete filepath | ||||
rescue Exception => e | |||||
rescue => e | |||||
logger.error "Unable to delete file #{filepath}: #{e.message}" if logger | logger.error "Unable to delete file #{filepath}: #{e.message}" if logger | ||||
end | end | ||||
end | end |
# Receives an email and rescues any exception | # Receives an email and rescues any exception | ||||
def self.safe_receive(*args) | def self.safe_receive(*args) | ||||
receive(*args) | receive(*args) | ||||
rescue Exception => e | |||||
rescue => e | |||||
Rails.logger.error "MailHandler: an unexpected error occurred when receiving email: #{e.message}" | Rails.logger.error "MailHandler: an unexpected error occurred when receiving email: #{e.message}" | ||||
return false | return false | ||||
end | end |
# Log errors when raise_delivery_errors is set to false, Rails does not | # Log errors when raise_delivery_errors is set to false, Rails does not | ||||
mail.raise_delivery_errors = true | mail.raise_delivery_errors = true | ||||
super | super | ||||
rescue Exception => e | |||||
rescue => e | |||||
if ActionMailer::Base.raise_delivery_errors | if ActionMailer::Base.raise_delivery_errors | ||||
raise e | raise e | ||||
else | else |
if self == ::Query | if self == ::Query | ||||
# Visibility depends on permissions for each subclass, | # Visibility depends on permissions for each subclass, | ||||
# raise an error if the scope is called from Query (eg. Query.visible) | # 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 | end | ||||
user = args.shift || User.current | user = args.shift || User.current |
ret = "" | ret = "" | ||||
begin | begin | ||||
ret = self.scm_adapter_class.client_command if self.scm_adapter_class | 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}" | logger.error "scm: error during get command: #{e.message}" | ||||
end | end | ||||
ret | ret | ||||
ret = "" | ret = "" | ||||
begin | begin | ||||
ret = self.scm_adapter_class.client_version_string if self.scm_adapter_class | 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}" | logger.error "scm: error during get version string: #{e.message}" | ||||
end | end | ||||
ret | ret | ||||
ret = false | ret = false | ||||
begin | begin | ||||
ret = self.scm_adapter_class.client_available if self.scm_adapter_class | 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}" | logger.error "scm: error during get scm available: #{e.message}" | ||||
end | end | ||||
ret | ret |
def default_branch | def default_branch | ||||
scm.default_branch | scm.default_branch | ||||
rescue Exception => e | |||||
rescue => e | |||||
logger.error "git: error during get default branch: #{e.message}" | logger.error "git: error during get default branch: #{e.message}" | ||||
nil | nil | ||||
end | end |
private | private | ||||
def check_integrity | 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 | ||||
end | end |
begin | begin | ||||
raise if items_per_page == 0 || @no_of_issues == 0 | raise if items_per_page == 0 || @no_of_issues == 0 | ||||
rescue Exception => e | |||||
rescue => e | |||||
puts "No changelog items to process.\n" + | puts "No changelog items to process.\n" + | ||||
"Make sure to provide a valid version id as the -i parameter." | "Make sure to provide a valid version id as the -i parameter." | ||||
exit | exit |
if File.exists?(file) | if File.exists?(file) | ||||
begin | begin | ||||
instance_eval File.read(file) | 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}." | puts "An error occurred while loading the routes definition of #{File.basename(plugin_dir)} plugin (#{file}): #{e.message}." | ||||
exit 1 | exit 1 | ||||
end | end |
def read_key_from_file(filename) | def read_key_from_file(filename) | ||||
begin | begin | ||||
self.key = File.read(filename).strip | self.key = File.read(filename).strip | ||||
rescue Exception => e | |||||
rescue => e | |||||
$stderr.puts "Unable to read the key from #{filename}:\n#{e.message}" | $stderr.puts "Unable to read the key from #{filename}:\n#{e.message}" | ||||
exit 1 | exit 1 | ||||
end | end |
def read_key_from_file(filename) | def read_key_from_file(filename) | ||||
begin | begin | ||||
$api_key = File.read(filename).strip | $api_key = File.read(filename).strip | ||||
rescue Exception => e | |||||
rescue => e | |||||
$stderr.puts "Unable to read the key from #{filename}: #{e.message}" | $stderr.puts "Unable to read the key from #{filename}: #{e.message}" | ||||
exit 1 | exit 1 | ||||
end | end |
base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, '')) | base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, '')) | ||||
begin | begin | ||||
FileUtils.mkdir_p(base_target_dir) | FileUtils.mkdir_p(base_target_dir) | ||||
rescue Exception => e | |||||
rescue => e | |||||
raise "Could not create directory #{base_target_dir}: " + e.message | raise "Could not create directory #{base_target_dir}: " + e.message | ||||
end | end | ||||
end | end | ||||
target_dir = File.join(destination, dir.gsub(source, '')) | target_dir = File.join(destination, dir.gsub(source, '')) | ||||
begin | begin | ||||
FileUtils.mkdir_p(target_dir) | FileUtils.mkdir_p(target_dir) | ||||
rescue Exception => e | |||||
rescue => e | |||||
raise "Could not create directory #{target_dir}: " + e.message | raise "Could not create directory #{target_dir}: " + e.message | ||||
end | end | ||||
end | end | ||||
unless File.exist?(target) && FileUtils.identical?(file, target) | unless File.exist?(target) && FileUtils.identical?(file, target) | ||||
FileUtils.cp(file, target) | FileUtils.cp(file, target) | ||||
end | end | ||||
rescue Exception => e | |||||
rescue => e | |||||
raise "Could not copy #{file} to #{target}: " + e.message | raise "Could not copy #{file} to #{target}: " + e.message | ||||
end | end | ||||
end | end |
io.close_write unless options[:write_stdin] | io.close_write unless options[:write_stdin] | ||||
block.call(io) if block_given? | block.call(io) if block_given? | ||||
end | 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) | msg = strip_credential(e.message) | ||||
# The command failed, log it and re-raise | # The command failed, log it and re-raise | ||||
logmsg = "SCM command failed, " | logmsg = "SCM command failed, " | ||||
str.force_encoding(from) | str.force_encoding(from) | ||||
begin | begin | ||||
str.encode(to) | str.encode(to) | ||||
rescue Exception => err | |||||
rescue => err | |||||
logger.error("failed to convert from #{from} to #{to}. #{err}") | logger.error("failed to convert from #{from} to #{to}. #{err}") | ||||
nil | nil | ||||
end | end |
:lastrev => Revision.new(:revision => tip['revision'], | :lastrev => Revision.new(:revision => tip['revision'], | ||||
:scmid => tip['node'])) | :scmid => tip['node'])) | ||||
# rescue HgCommandAborted | # rescue HgCommandAborted | ||||
rescue Exception => e | |||||
rescue => e | |||||
logger.error "hg: error during getting info: #{e.message}" | logger.error "hg: error during getting info: #{e.message}" | ||||
nil | nil | ||||
end | end |
}) | }) | ||||
}) | }) | ||||
end | end | ||||
rescue Exception => e | |||||
rescue => e | |||||
logger.error("Error parsing svn output: #{e.message}") | logger.error("Error parsing svn output: #{e.message}") | ||||
logger.error("Output was:\n #{output}") | logger.error("Output was:\n #{output}") | ||||
end | end |
begin | begin | ||||
Mailer.deliver_test_email(user) | Mailer.deliver_test_email(user) | ||||
puts l(:notice_email_sent, user.mail) | puts l(:notice_email_sent, user.mail) | ||||
rescue Exception => e | |||||
rescue => e | |||||
abort l(:notice_email_error, e.message) | abort l(:notice_email_error, e.message) | ||||
end | end | ||||
end | end |
puts "parsing #{filename}..." | puts "parsing #{filename}..." | ||||
begin | begin | ||||
parser.parse File.open(filename) | parser.parse File.open(filename) | ||||
rescue Exception => e1 | |||||
rescue => e1 | |||||
puts(e1.message) | puts(e1.message) | ||||
puts("") | puts("") | ||||
end | end | ||||
end | end | ||||
rescue Exception => e | |||||
rescue => e | |||||
puts(e.message) | puts(e.message) | ||||
end | end | ||||
end | end |
raise "This directory doesn't exist!" unless File.directory?(path) | raise "This directory doesn't exist!" unless File.directory?(path) | ||||
raise "#{trac_attachments_directory} doesn't exist!" unless File.directory?(trac_attachments_directory) | raise "#{trac_attachments_directory} doesn't exist!" unless File.directory?(trac_attachments_directory) | ||||
@@trac_directory | @@trac_directory | ||||
rescue Exception => e | |||||
rescue => e | |||||
puts e | puts e | ||||
return false | return false | ||||
end | end | ||||
# If adapter is sqlite or sqlite3, make sure that trac.db exists | # 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) | raise "#{trac_db_path} doesn't exist!" if %w(sqlite3).include?(adapter) && !File.exist?(trac_db_path) | ||||
@@trac_adapter = adapter | @@trac_adapter = adapter | ||||
rescue Exception => e | |||||
rescue => e | |||||
puts e | puts e | ||||
return false | return false | ||||
end | end |
def test_load_default_configuration_data_should_rescue_error | def test_load_default_configuration_data_should_rescue_error | ||||
delete_configuration_data | 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 => { | post :default_configuration, :params => { | ||||
:lang => 'fr' | :lang => 'fr' | ||||
} | } | ||||
end | end | ||||
def test_test_email_failure_should_display_the_error | 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 | post :test_email | ||||
assert_redirected_to '/settings?tab=notifications' | assert_redirected_to '/settings?tab=notifications' | ||||
assert_match /Some error message/, flash[:error] | assert_match /Some error message/, flash[:error] |
def self.ldap_configured? | def self.ldap_configured? | ||||
@test_ldap = Net::LDAP.new(:host => $redmine_test_ldap_server, :port => 389) | @test_ldap = Net::LDAP.new(:host => $redmine_test_ldap_server, :port => 389) | ||||
return @test_ldap.bind | return @test_ldap.bind | ||||
rescue Exception => e | |||||
rescue => e | |||||
# LDAP is not listening | # LDAP is not listening | ||||
return nil | return nil | ||||
end | end |
ActiveRecord::Base.connection_pool.with_connection do | ActiveRecord::Base.connection_pool.with_connection do | ||||
begin | begin | ||||
yield | yield | ||||
rescue Exception => e | |||||
rescue => e | |||||
Thread.current[:exception] = e.message | Thread.current[:exception] = e.message | ||||
end | end | ||||
end | end |
end | end | ||||
def test_safe_receive_should_rescue_exceptions_and_return_false | 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 | assert_equal false, MailHandler.safe_receive | ||||
end | end |
def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true | def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true | ||||
mail = Mailer.test_email(User.find(1)) | 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 | ActionMailer::Base.raise_delivery_errors = true | ||||
assert_raise Exception, "delivery error" do | |||||
assert_raise StandardError, "delivery error" do | |||||
mail.deliver | mail.deliver | ||||
end | end | ||||
ensure | ensure | ||||
def test_should_log_delivery_errors_when_raise_delivery_errors_is_false | def test_should_log_delivery_errors_when_raise_delivery_errors_is_false | ||||
mail = Mailer.test_email(User.find(1)) | 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") | Rails.logger.expects(:error).with("Email delivery error: delivery error") | ||||
ActionMailer::Base.raise_delivery_errors = false | ActionMailer::Base.raise_delivery_errors = false |
c2.reload.destroy | c2.reload.destroy | ||||
c1.reload.destroy | c1.reload.destroy | ||||
end | end | ||||
rescue Exception => e | |||||
rescue => e | |||||
Thread.current[:exception] = e.message | Thread.current[:exception] = e.message | ||||
end | end | ||||
end | end |
tracker = Tracker.find(1) | tracker = Tracker.find(1) | ||||
assert_no_difference 'Tracker.count' do | assert_no_difference 'Tracker.count' do | ||||
assert_raise Exception do | |||||
assert_raise StandardError do | |||||
tracker.destroy | tracker.destroy | ||||
end | end | ||||
end | end |