diff --git a/lib/vagrant/action/box/unpackage.rb b/lib/vagrant/action/box/unpackage.rb index 811a782c6..9186ef594 100644 --- a/lib/vagrant/action/box/unpackage.rb +++ b/lib/vagrant/action/box/unpackage.rb @@ -24,7 +24,7 @@ module Vagrant def call(env) @env = env - return if !setup_box_directory + setup_box_directory decompress @app.call(@env) @@ -37,14 +37,10 @@ module Vagrant end def setup_box_directory - if File.directory?(@env["box"].directory) - @env.error!(:box_already_exists, :box_name => @env["box"].name) - return false - end + raise Errors::BoxAlreadyExists.new(:name => @env["box"].name) if File.directory?(@env["box"].directory) FileUtils.mkdir_p(@env["box"].directory) @box_directory = @env["box"].directory - true end def decompress diff --git a/lib/vagrant/action/box/verify.rb b/lib/vagrant/action/box/verify.rb index 62ead1f60..b42b0d500 100644 --- a/lib/vagrant/action/box/verify.rb +++ b/lib/vagrant/action/box/verify.rb @@ -12,7 +12,7 @@ module Vagrant env.ui.info "vagrant.actions.box.verify.verifying" VirtualBox::Appliance.new(env["box"].ovf_file) rescue Exception - return env.error!(:box_verification_failed) + raise Errors::BoxVerificationFailed.new end @app.call(env) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index d52473675..88f08b7d8 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -38,6 +38,11 @@ module Vagrant error_key(:base_vm_not_found) end + class BoxAlreadyExists < VagrantError + status_code(14) + error_key(:already_exists, "vagrant.actions.box.unpackage") + end + class BoxDownloadUnknownType < VagrantError status_code(13) error_key(:unknown_type, "vagrant.actions.box.download") @@ -48,6 +53,11 @@ module Vagrant error_key(:box_not_found) end + class BoxVerificationFailed < VagrantError + status_code(15) + error_key(:failed, "vagrant.actions.box.verify") + end + class CLIMissingEnvironment < VagrantError status_code(1) error_key(:cli_missing_env) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index e09441fb8..487dae2d5 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -181,8 +181,17 @@ en: unknown_type: "Unknown or unsupported URI type given for box download." unpackage: extracting: "Extracting box..." + already_exists: |- + A box already exists under the name of '%{name}'. This may or may + not be the same box you are trying to add. Please use another name + or remove the previous box then try to add it again. verify: verifying: "Verifying box..." + failed: |- + The box file you're attempting to add is invalid. This can be + commonly attributed to typos in the path given to the box add + command. Another common case of this is invalid packaging of the + box itself. general: package: diff --git a/templates/strings.yml b/templates/strings.yml index 7f06cf521..91ce2df51 100644 --- a/templates/strings.yml +++ b/templates/strings.yml @@ -7,9 +7,6 @@ #--------------------------------------------------------------------- # CATEGORY: Error Messages #--------------------------------------------------------------------- -:box_already_exists: |- - This box appears to already exist! Please call `vagrant box remove <%= box_name %>` - and then try to add it again. :box_download_http_socket_error: |- An error occurred while trying to download the specified box. This most often happens if there is no internet connection or the address is @@ -34,9 +31,6 @@ The box must be added through the `vagrant box add` command. Please view the documentation associated with the command for more information. -:box_verification_failed: |- - The specified box is invalid. This can commonly be attributed to incorrectly - typing in the path to the box or invalid packaging of the box. :box_not_specified: |- No base box was specified! A base box is required as a staring point for every vagrant virtual machine. Please specify one in your Vagrantfile diff --git a/test/vagrant/action/box/unpackage_test.rb b/test/vagrant/action/box/unpackage_test.rb index 022ffa421..a5373eda9 100644 --- a/test/vagrant/action/box/unpackage_test.rb +++ b/test/vagrant/action/box/unpackage_test.rb @@ -23,13 +23,6 @@ class UnpackageBoxActionTest < Test::Unit::TestCase @app.expects(:call).with(@env) @instance.call(@env) end - - should "halt the chain if setting up the box directory fails" do - @instance.expects(:setup_box_directory).returns(false) - @instance.expects(:decompress).never - @app.expects(:call).never - @instance.call(@env) - end end context "cleaning up" do @@ -59,9 +52,9 @@ class UnpackageBoxActionTest < Test::Unit::TestCase should "error the environment if the box already exists" do File.expects(:directory?).returns(true) - assert !@instance.setup_box_directory - assert @env.error? - assert_equal :box_already_exists, @env.error.first + assert_raises(Vagrant::Errors::BoxAlreadyExists) { + @instance.setup_box_directory + } end should "create the directory" do diff --git a/test/vagrant/action/box/verify_test.rb b/test/vagrant/action/box/verify_test.rb index e50966ca9..e12441aea 100644 --- a/test/vagrant/action/box/verify_test.rb +++ b/test/vagrant/action/box/verify_test.rb @@ -27,9 +27,9 @@ class VerifyBoxActionTest < Test::Unit::TestCase should "halt chain if verification fails" do VirtualBox::Appliance.expects(:new).with(@env["box"].ovf_file).raises(Exception) @app.expects(:call).with(@env).never - @instance.call(@env) - assert @env.error? - assert_equal :box_verification_failed, @env.error.first + assert_raises(Vagrant::Errors::BoxVerificationFailed) { + @instance.call(@env) + } end end end diff --git a/test/vagrant/action/warden_test.rb b/test/vagrant/action/warden_test.rb index 6b8f5abfd..4cb6b55b7 100644 --- a/test/vagrant/action/warden_test.rb +++ b/test/vagrant/action/warden_test.rb @@ -86,11 +86,6 @@ class ActionWardenTest < Test::Unit::TestCase @instance.begin_rescue(new_env) end - should "call error and exit" do - @instance.expects(:error_and_exit) - @instance.begin_rescue(new_env) - end - should "call exit if the environment is interupted" do @instance.expects(:exit) env = new_env