Skip to content

A platform for community discussion. Free, open, simple.

Remove more uses of `rescue nil`.

Guo Xiang Tan0d74c30fa70b
diff --git a/lib/search.rb b/lib/search.rb
index a391ebbd5a3..a61a36eb0f2 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -73,7 +73,10 @@ class Search
return if day == 0 || month == 0 || day > 31 || month > 12
- return Time.zone.parse("#{year}-#{month}-#{day}") rescue nil
+ return begin
+ Time.zone.parse("#{year}-#{month}-#{day}")
+ rescue ArgumentError
+ end
end
if str.downcase == "yesterday"
diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rb
index 82efa7fd439..ec13cc87498 100644
--- a/plugins/poll/plugin.rb
+++ b/plugins/poll/plugin.rb
@@ -66,7 +66,12 @@ after_initialize do
# ensure no race condition when poll is automatically closed
if poll["close"].present?
- close_date = Time.zone.parse(poll["close"]) rescue nil
+ close_date =
+ begin
+ close_date = Time.zone.parse(poll["close"])
+ rescue ArgumentError
+ end
+
raise StandardError.new I18n.t("poll.poll_must_be_open_to_vote") if close_date && close_date <= Time.zone.now
end
@@ -159,7 +164,12 @@ after_initialize do
Jobs.cancel_scheduled_job(:close_poll, post_id: post.id, poll_name: name)
if poll["status"] == "open" && poll["close"].present?
- close_date = Time.zone.parse(poll["close"]) rescue nil
+ close_date =
+ begin
+ Time.zone.parse(poll["close"])
+ rescue ArgumentError
+ end
+
Jobs.enqueue_at(close_date, :close_poll, post_id: post.id, poll_name: name) if close_date && close_date > Time.zone.now
end
end