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:
Guo Xiang Tan
2018-03-28 16:20:08 +08:00
parent efb19dbdaf
commit 142571bba0
39 changed files with 228 additions and 136 deletions

View File

@@ -42,8 +42,8 @@ class HandleChunkUpload
tmp_directory = @params[:tmp_directory]
# delete destination files
File.delete(upload_path) rescue nil
File.delete(tmp_upload_path) rescue nil
File.delete(upload_path)
File.delete(tmp_upload_path)
# merge all the chunks
File.open(tmp_upload_path, "a") do |file|
@@ -59,7 +59,7 @@ class HandleChunkUpload
FileUtils.mv(tmp_upload_path, upload_path, force: true)
# remove tmp directory
FileUtils.rm_rf(tmp_directory) rescue nil
FileUtils.rm_rf(tmp_directory)
end
end

View File

@@ -405,8 +405,7 @@ class PostAlerter
)
if created.id && !existing_notification && NOTIFIABLE_TYPES.include?(type) && !user.suspended?
# we may have an invalid post somehow, dont blow up
post_url = original_post.url rescue nil
post_url = original_post.url
if post_url
payload = {
notification_type: type,