Skip to content

Commit 1e1e4f1

Browse files
AZQ1994claude
andcommitted
Treat missing marshal files as empty record sets
MarshalLoader#read_raw raised Errno::ENOENT when the dump file did not exist, which prevented bootstrapping a dataset before any dump was produced. Align the behavior with QueryLoader's empty-table fallback so loading a missing table yields an empty record set instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3c1c52a commit 1e1e4f1

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

lib/simple_master/loader/marshal_loader.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ module SimpleMaster
44
class Loader
55
class MarshalLoader < Loader
66
def read_raw(table)
7-
File.read("#{@options[:path]}/#{table.klass.table_name}.marshal")
7+
path = "#{@options[:path]}/#{table.klass.table_name}.marshal"
8+
return nil unless File.exist?(path)
9+
10+
File.read(path)
811
end
912

1013
def build_records(_klass, raw)
14+
return [] if raw.nil?
15+
1116
Marshal.load(raw) # rubocop:disable Security/MarshalLoad
1217
end
1318
end

spec/simple_master/loader/marshal_loader_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,19 @@
2323
end
2424
end
2525
end
26+
27+
it "treats missing marshal files as empty record sets instead of raising" do
28+
Dir.mktmpdir do |dir|
29+
loader = described_class.new(path: dir)
30+
dataset = SimpleMaster::Storage::Dataset.new(loader: loader)
31+
32+
expect { dataset.load }.not_to raise_error
33+
34+
SimpleMaster.use_dataset(dataset) do
35+
expect(Weapon.all).to eq([])
36+
expect(Level.all).to eq([])
37+
expect(Enemy.all).to eq([])
38+
end
39+
end
40+
end
2641
end

0 commit comments

Comments
 (0)