If JSON parsing fails on reading the active list, just set it to an empty hash
This commit is contained in:
parent
699fa2ce77
commit
4d042da99b
|
@ -26,7 +26,11 @@ module Vagrant
|
||||||
@list ||= {}
|
@list ||= {}
|
||||||
return @list unless File.file?(path)
|
return @list unless File.file?(path)
|
||||||
File.open(path, "r") do |f|
|
File.open(path, "r") do |f|
|
||||||
|
begin
|
||||||
@list = JSON.parse(f.read)
|
@list = JSON.parse(f.read)
|
||||||
|
rescue Exception
|
||||||
|
@list = {}
|
||||||
|
end
|
||||||
|
|
||||||
# This forces earlier versions of Vagrant to use the new hash
|
# This forces earlier versions of Vagrant to use the new hash
|
||||||
# format. Clearing out the old data isn't a big deal since it
|
# format. Clearing out the old data isn't a big deal since it
|
||||||
|
|
|
@ -57,6 +57,18 @@ class ActiveListTest < Test::Unit::TestCase
|
||||||
assert result.equal?(@list.list)
|
assert result.equal?(@list.list)
|
||||||
assert result.equal?(@list.list)
|
assert result.equal?(@list.list)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "be an empty hash if JSON parsing raises an exception" do
|
||||||
|
file = mock("file")
|
||||||
|
file.stubs(:read)
|
||||||
|
File.expects(:file?).returns(true)
|
||||||
|
File.expects(:open).with(@list.path, 'r').once.yields(file)
|
||||||
|
JSON.expects(:parse).raises(Exception)
|
||||||
|
|
||||||
|
assert_nothing_raised do
|
||||||
|
assert_equal Hash.new, @list.list(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "filter list" do
|
context "filter list" do
|
||||||
|
|
Loading…
Reference in New Issue