mirror of
https://github.com/discourse/discourse.git
synced 2026-08-13 06:25:11 -05:00
Remove use of rescue nil.
* `rescue nil` is a really bad pattern to use in our code base. We should rescue errors that we expect the code to throw and not rescue everything because we're unsure of what errors the code would throw. This would reduce the amount of pain we face when debugging why something isn't working as expexted. I've been bitten countless of times by errors being swallowed as a result during debugging sessions.
This commit is contained in:
@@ -16,7 +16,10 @@ class TopicLinkClick < ActiveRecord::Base
|
||||
url = args[:url][0...TopicLink.max_url_length]
|
||||
return nil if url.blank?
|
||||
|
||||
uri = URI.parse(url) rescue nil
|
||||
uri = begin
|
||||
URI.parse(url)
|
||||
rescue URI::InvalidURIError
|
||||
end
|
||||
|
||||
urls = Set.new
|
||||
urls << url
|
||||
@@ -43,7 +46,11 @@ class TopicLinkClick < ActiveRecord::Base
|
||||
# add a cdn link
|
||||
if uri
|
||||
if Discourse.asset_host.present?
|
||||
cdn_uri = URI.parse(Discourse.asset_host) rescue nil
|
||||
cdn_uri = begin
|
||||
URI.parse(Discourse.asset_host)
|
||||
rescue URI::InvalidURIError
|
||||
end
|
||||
|
||||
if cdn_uri && cdn_uri.hostname == uri.hostname && uri.path.starts_with?(cdn_uri.path)
|
||||
is_cdn_link = true
|
||||
urls << uri.path[cdn_uri.path.length..-1]
|
||||
@@ -51,7 +58,11 @@ class TopicLinkClick < ActiveRecord::Base
|
||||
end
|
||||
|
||||
if SiteSetting.Upload.s3_cdn_url.present?
|
||||
cdn_uri = URI.parse(SiteSetting.Upload.s3_cdn_url) rescue nil
|
||||
cdn_uri = begin
|
||||
URI.parse(SiteSetting.Upload.s3_cdn_url)
|
||||
rescue URI::InvalidURIError
|
||||
end
|
||||
|
||||
if cdn_uri && cdn_uri.hostname == uri.hostname && uri.path.starts_with?(cdn_uri.path)
|
||||
is_cdn_link = true
|
||||
path = uri.path[cdn_uri.path.length..-1]
|
||||
|
||||
Reference in New Issue
Block a user