mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #5125 from winston/log_exception_when_cache_read_fails
#read_entry in ActiveSupport::Cache::FileStore should log details of the exception when an exception is thrown
This commit is contained in:
commit
e44009aa2b
2 changed files with 11 additions and 1 deletions
|
@ -81,7 +81,8 @@ module ActiveSupport
|
|||
if File.exist?(file_name)
|
||||
File.open(file_name) { |f| Marshal.load(f) }
|
||||
end
|
||||
rescue
|
||||
rescue => e
|
||||
logger.error("FileStoreError (#{e}): #{e.message}") if logger
|
||||
nil
|
||||
end
|
||||
|
||||
|
|
|
@ -553,6 +553,9 @@ class FileStoreTest < ActiveSupport::TestCase
|
|||
@cache = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60)
|
||||
@peek = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60)
|
||||
@cache_with_pathname = ActiveSupport::Cache.lookup_store(:file_store, Pathname.new(cache_dir), :expires_in => 60)
|
||||
|
||||
@buffer = StringIO.new
|
||||
@cache.logger = ActiveSupport::Logger.new(@buffer)
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
@ -612,6 +615,12 @@ class FileStoreTest < ActiveSupport::TestCase
|
|||
ActiveSupport::Cache::FileStore.new('/test/cache/directory').delete_matched(/does_not_exist/)
|
||||
end
|
||||
end
|
||||
|
||||
def test_log_exception_when_cache_read_fails
|
||||
File.expects(:exist?).raises(StandardError, "failed")
|
||||
@cache.send(:read_entry, "winston", {})
|
||||
assert_present @buffer.string
|
||||
end
|
||||
end
|
||||
|
||||
class MemoryStoreTest < ActiveSupport::TestCase
|
||||
|
|
Loading…
Reference in a new issue