Skip to content

Commit f8724a2

Browse files
committed
Reset emoji cache if Marshal.load throws
1 parent 4348a17 commit f8724a2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

emoji.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def to_emoji
5252
end
5353
end.parse!(option_array)
5454

55-
if $debug_mode
55+
def reset_marshal_cache
5656
File.open(MARSHAL_TMP_FILE, File::RDWR|File::CREAT, 0644) do |f|
5757
fc = {
5858
'search_strings' => {},
@@ -84,8 +84,13 @@ def to_emoji
8484
f.write(Marshal.dump(fc))
8585
f.flush
8686
f.truncate(f.pos)
87+
fc
8788
end
89+
end
8890

91+
if $debug_mode
92+
reset_marshal_cache
93+
STDERR.puts "Marshal cache reset!"
8994
puts JSON.pretty_generate({
9095
:items => [
9196
{
@@ -99,7 +104,12 @@ def to_emoji
99104
exit 0
100105
end
101106

102-
EMOJI_OBJ = File.open(MARSHAL_TMP_FILE, File::RDWR|File::CREAT, 0644) {|f| Marshal.load(f.read)}
107+
EMOJI_OBJ = begin
108+
File.open(MARSHAL_TMP_FILE, File::RDWR|File::CREAT, 0644) {|f| Marshal.load(f.read)}
109+
rescue ArgumentError
110+
STDERR.puts "Marshal cache could not be loaded. Resetting!"
111+
reset_marshal_cache
112+
end
103113

104114
### SEARCH SHIT
105115

0 commit comments

Comments
 (0)