From d73895312ef70602abd10e3f3c36cb12428e9a34 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 29 Aug 2019 00:24:00 -0500 Subject: [PATCH] Avoid swallowing exceptions unnecessarily. --- ...lias_and_implication_imports_controller.rb | 3 --- app/controllers/counts_controller.rb | 1 - .../moderator/post/posts_controller.rb | 2 -- app/controllers/user_upgrades_controller.rb | 1 + app/models/artist.rb | 20 ++++++------------- app/models/saved_search.rb | 2 -- .../post_set_presenters/wiki_page.rb | 2 -- 7 files changed, 7 insertions(+), 24 deletions(-) diff --git a/app/controllers/admin/alias_and_implication_imports_controller.rb b/app/controllers/admin/alias_and_implication_imports_controller.rb index ad4998e06..8e71f819d 100644 --- a/app/controllers/admin/alias_and_implication_imports_controller.rb +++ b/app/controllers/admin/alias_and_implication_imports_controller.rb @@ -10,9 +10,6 @@ module Admin @importer.process! flash[:notice] = "Import queued" redirect_to new_admin_alias_and_implication_import_path - rescue => x - flash[:notice] = x.to_s - redirect_to new_admin_alias_and_implication_import_path end end end diff --git a/app/controllers/counts_controller.rb b/app/controllers/counts_controller.rb index 795ec7d13..11e2c05a3 100644 --- a/app/controllers/counts_controller.rb +++ b/app/controllers/counts_controller.rb @@ -1,6 +1,5 @@ class CountsController < ApplicationController respond_to :xml, :json - rescue_from Post::TimeoutError, with: :rescue_exception def posts @count = Post.fast_count( diff --git a/app/controllers/moderator/post/posts_controller.rb b/app/controllers/moderator/post/posts_controller.rb index ee0b4f61f..76700a90b 100644 --- a/app/controllers/moderator/post/posts_controller.rb +++ b/app/controllers/moderator/post/posts_controller.rb @@ -39,8 +39,6 @@ module Moderator def expunge @post = ::Post.find(params[:id]) @post.expunge! - rescue StandardError => x - @error = x end def confirm_ban diff --git a/app/controllers/user_upgrades_controller.rb b/app/controllers/user_upgrades_controller.rb index 47b1749ca..e295b16a1 100644 --- a/app/controllers/user_upgrades_controller.rb +++ b/app/controllers/user_upgrades_controller.rb @@ -51,6 +51,7 @@ class UserUpgradesController < ApplicationController @user.promote_to!(level, is_upgrade: true) flash[:success] = true rescue Stripe::CardError => e + DanbooruLogger.log(e) flash[:error] = e.message end diff --git a/app/models/artist.rb b/app/models/artist.rb index 06c39d05f..e7e1b04ba 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -416,14 +416,10 @@ class Artist < ApplicationRecord ti = TagImplication.where(:antecedent_name => name, :consequent_name => "banned_artist").first ti.destroy if ti - begin - Post.tag_match(name).where("true /* Artist.unban */").each do |post| - post.unban! - fixed_tags = post.tag_string.sub(/(?:\A| )banned_artist(?:\Z| )/, " ").strip - post.update(tag_string: fixed_tags) - end - rescue Post::SearchError - # swallow + Post.tag_match(name).where("true /* Artist.unban */").each do |post| + post.unban! + fixed_tags = post.tag_string.sub(/(?:\A| )banned_artist(?:\Z| )/, " ").strip + post.update(tag_string: fixed_tags) end update_column(:is_banned, false) @@ -435,12 +431,8 @@ class Artist < ApplicationRecord def ban! Post.transaction do CurrentUser.without_safe_mode do - begin - Post.tag_match(name).where("true /* Artist.ban */").each do |post| - post.ban! - end - rescue Post::SearchError - # swallow + Post.tag_match(name).where("true /* Artist.ban */").each do |post| + post.ban! end # potential race condition but unlikely diff --git a/app/models/saved_search.rb b/app/models/saved_search.rb index c57df5754..9c9c06140 100644 --- a/app/models/saved_search.rb +++ b/app/models/saved_search.rb @@ -101,8 +101,6 @@ class SavedSearch < ApplicationRecord redis.sadd(redis_key, post_ids) redis.expire(redis_key, REDIS_EXPIRY) end - rescue Exception - # swallow end end end diff --git a/app/presenters/post_set_presenters/wiki_page.rb b/app/presenters/post_set_presenters/wiki_page.rb index 932eb2c3b..4f34d17b1 100644 --- a/app/presenters/post_set_presenters/wiki_page.rb +++ b/app/presenters/post_set_presenters/wiki_page.rb @@ -2,8 +2,6 @@ module PostSetPresenters class WikiPage < PostSetPresenters::Post def posts @post_set.posts - rescue ActiveRecord::StatementInvalid, PG::Error - [] end def post_previews_html(template)