Skip to content

Commit 0bb3579

Browse files
Copilotnhorton
andcommitted
Add error handling for write and delete operations
Co-authored-by: nhorton <[email protected]>
1 parent 8e39728 commit 0bb3579

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/active_support/cache/source_control_cache_store.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def read_entry(key, **options)
7373
# @param key [String] The cache key
7474
# @param entry [ActiveSupport::Cache::Entry] The cache entry
7575
# @param options [Hash] Options (expiration is ignored)
76-
# @return [Boolean] Always returns true
76+
# @return [Boolean] Returns true on success, false on failure
7777
def write_entry(key, entry, **options)
7878
hash = hash_key(key)
7979

@@ -84,6 +84,9 @@ def write_entry(key, entry, **options)
8484
File.write(value_path(hash), serialize_entry(entry, **options))
8585

8686
true
87+
rescue => e
88+
# Return false if write fails (permissions, disk space, etc.)
89+
false
8790
end
8891

8992
# Delete an entry from the cache
@@ -97,8 +100,18 @@ def delete_entry(key, **options)
97100
value_file = value_path(hash)
98101

99102
deleted = false
100-
deleted = true if File.exist?(key_file) && File.delete(key_file)
101-
deleted = true if File.exist?(value_file) && File.delete(value_file)
103+
104+
begin
105+
deleted = true if File.exist?(key_file) && File.delete(key_file)
106+
rescue => e
107+
# Ignore errors, continue trying to delete value file
108+
end
109+
110+
begin
111+
deleted = true if File.exist?(value_file) && File.delete(value_file)
112+
rescue => e
113+
# Ignore errors
114+
end
102115

103116
deleted
104117
end

0 commit comments

Comments
 (0)