Skip to content

Commit

Permalink
#read_entry in ActiveSupport::Cache::FileStore should log details of …
Browse files Browse the repository at this point in the history
…the exception when an exception is thrown.
  • Loading branch information
winston committed Feb 22, 2012
1 parent a95f730 commit b52c66f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion activesupport/lib/active_support/cache/file_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def read_entry(key, options)
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

Expand Down
9 changes: 9 additions & 0 deletions activesupport/test/caching_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@ def setup
@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
Expand Down Expand Up @@ -591,6 +594,12 @@ def test_delete_matched_when_cache_directory_does_not_exist
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
Expand Down

0 comments on commit b52c66f

Please sign in to comment.