diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b3a0d78c..e72155d95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ BUG FIXES: so on work properly. - When there is no route to host for SSH, re-establish a new connection. - `vagrant package` once again works, no more nil error. [GH-1423] + - Human friendly error when "metadata.json" is missing in a box. ## 1.1.0 (March 14, 2013) diff --git a/lib/vagrant/box.rb b/lib/vagrant/box.rb index 56e10760a..56daad812 100644 --- a/lib/vagrant/box.rb +++ b/lib/vagrant/box.rb @@ -43,7 +43,10 @@ module Vagrant @name = name @provider = provider @directory = directory - @metadata = JSON.parse(directory.join("metadata.json").read) + + metadata_file = directory.join("metadata.json") + raise Errors::BoxMetadataFileNotFound, :name => @name if !metadata_file.file? + @metadata = JSON.parse(directory.join("metadata.json").read) @logger = Log4r::Logger.new("vagrant::box") end diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 14b7274e6..135d6ba35 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -99,6 +99,10 @@ module Vagrant error_key(:unknown_type, "vagrant.actions.box.download") end + class BoxMetadataFileNotFound < VagrantError + error_key(:box_metadata_file_not_found) + end + class BoxNotFound < VagrantError error_key(:box_not_found) end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index a4ce8eab2..0300b3287 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -52,6 +52,15 @@ en: Active provider: %{active_provider} Requested provider: %{requested_provider} base_vm_not_found: The base VM with the name '%{name}' was not found. + box_metadata_file_not_found: |- + The "metadata.json" file for the box '%{name}' was not found. + Boxes require this file in order for Vagrant to determine the + provider it was made for. If you made the box, please add a + "metadata.json" file to it. If someone else made the box, please + notify the box creator that the box is corrupt. Documentation for + box file format can be found at the URL below: + + http://docs.vagrantup.com/v2/boxes/format.html box_not_found: Box '%{name}' could not be found. box_provider_doesnt_match: |- The box you attempted to add doesn't match the provider you specified. diff --git a/test/unit/vagrant/box_test.rb b/test/unit/vagrant/box_test.rb index e7eb81485..8176f19dd 100644 --- a/test/unit/vagrant/box_test.rb +++ b/test/unit/vagrant/box_test.rb @@ -14,6 +14,8 @@ describe Vagrant::Box do let(:directory) { environment.box2("foo", :virtualbox) } let(:instance) { described_class.new(name, provider, directory) } + subject { described_class.new(name, provider, directory) } + it "provides the name" do instance.name.should == name end @@ -38,6 +40,17 @@ describe Vagrant::Box do instance.metadata.should == data end + context "without a metadata file" do + before :each do + directory.join("metadata.json").delete + end + + it "should raise an exception" do + expect { subject }. + to raise_error(Vagrant::Errors::BoxMetadataFileNotFound) + end + end + describe "destroying" do it "should destroy an existing box" do # Verify that our "box" exists