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

@@ -110,7 +110,11 @@ class Stylesheet::Manager
if File.exists?(stylesheet_fullpath)
unless StylesheetCache.where(target: qualified_target, digest: digest).exists?
begin
source_map = File.read(source_map_fullpath) rescue nil
source_map = begin
File.read(source_map_fullpath)
rescue Errno::ENOENT
end
StylesheetCache.add(qualified_target, digest, File.read(stylesheet_fullpath), source_map)
rescue => e
Rails.logger.warn "Completely unexpected error adding contents of '#{stylesheet_fullpath}' to cache #{e}"