Fix crashing bug if .vagrant is invalid. [closes GH-496]

This commit is contained in:
Mitchell Hashimoto 2011-09-11 23:23:17 -07:00
parent 5d993e76ec
commit 1cfef2734a
3 changed files with 15 additions and 1 deletions

View File

@ -1,6 +1,7 @@
## 0.8.7 (unreleased)
- Fix regression with remote paths from chef-solo. [GH-431]
- Fix issue where Vagrant crashes if `.vagrant` file becomes invalid. [GH-496]
## 0.8.6 (August 28, 2011)

View File

@ -23,7 +23,12 @@ module Vagrant
if File.exist?(file_path)
File.open(file_path, "r") do |f|
merge!(JSON.parse(f.read))
begin
merge!(JSON.parse(f.read))
rescue JSON::ParserError
# Ignore if the data is invalid in the file.
# TODO: Log here.
end
end
end
end

View File

@ -23,6 +23,14 @@ class DataStoreTest < Test::Unit::TestCase
}
end
should "initialize just fine if the db file contains invalid data" do
file = tmp_path.join("data_store_empty_test")
File.open(file, "w") { |f| f.write("") }
instance = @klass.new(file)
assert instance.length == 0
end
should "be a hash with indifferent access" do
assert @instance.is_a?(Vagrant::Util::HashWithIndifferentAccess)
end