diff --git a/lib/vagrant/action/vm/boot.rb b/lib/vagrant/action/vm/boot.rb index ae71702dc..f969b34ad 100644 --- a/lib/vagrant/action/vm/boot.rb +++ b/lib/vagrant/action/vm/boot.rb @@ -8,16 +8,11 @@ module Vagrant end def call(env) - # Do nothing if the environment is erroneous - return if env.error? - @env = env # Start up the VM and wait for it to boot. boot - return env.error!(:vm_failed_to_boot) if !wait_for_boot - return if env.error? - + raise Errors::VMFailedToBoot.new if !wait_for_boot @app.call(env) end diff --git a/lib/vagrant/action/vm/check_box.rb b/lib/vagrant/action/vm/check_box.rb index 90526c6de..6d2318505 100644 --- a/lib/vagrant/action/vm/check_box.rb +++ b/lib/vagrant/action/vm/check_box.rb @@ -8,11 +8,11 @@ module Vagrant def call(env) box_name = env["config"].vm.box - return env.error!(:box_not_specified) if !box_name + raise Errors::BoxNotSpecified.new if !box_name if !Vagrant::Box.find(env.env , box_name) box_url = env["config"].vm.box_url - return env.error!(:box_specified_doesnt_exist, :box_name => box_name) if !box_url + raise Errors::BoxSpecifiedDoesntExist.new(:name => box_name) if !box_url env.ui.info "vagrant.actions.vm.check_box.not_found", :name => box_name Vagrant::Box.add(env.env, box_name, box_url) diff --git a/lib/vagrant/action/vm/clear_forwarded_ports.rb b/lib/vagrant/action/vm/clear_forwarded_ports.rb index 6e16a00cf..452c6d7cb 100644 --- a/lib/vagrant/action/vm/clear_forwarded_ports.rb +++ b/lib/vagrant/action/vm/clear_forwarded_ports.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), 'forward_ports_helpers') +require File.expand_path("../forward_ports_helpers", __FILE__) module Vagrant class Action diff --git a/lib/vagrant/action/vm/clear_nfs_exports.rb b/lib/vagrant/action/vm/clear_nfs_exports.rb index 1f4043d9b..291ece25d 100644 --- a/lib/vagrant/action/vm/clear_nfs_exports.rb +++ b/lib/vagrant/action/vm/clear_nfs_exports.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), 'nfs_helpers') +require File.expand_path("../nfs_helpers", __FILE__) module Vagrant class Action diff --git a/lib/vagrant/action/vm/export.rb b/lib/vagrant/action/vm/export.rb index c1bd70080..6040a287e 100644 --- a/lib/vagrant/action/vm/export.rb +++ b/lib/vagrant/action/vm/export.rb @@ -14,7 +14,7 @@ module Vagrant def call(env) @env = env - return env.error!(:vm_power_off_to_package) if !@env["vm"].vm.powered_off? + raise Errors::VMPowerOffToPackage.new if !@env["vm"].vm.powered_off? setup_temp_dir export diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 36e285600..fbd297b98 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -59,6 +59,16 @@ module Vagrant error_key(:box_not_found) end + class BoxNotSpecified < VagrantError + status_code(22) + error_key(:not_specified, "vagrant.actions.vm.check_box") + end + + class BoxSpecifiedDoesntExist < VagrantError + status_code(23) + error_key(:does_not_exist, "vagrant.actions.vm.check_box") + end + class BoxVerificationFailed < VagrantError status_code(15) error_key(:failed, "vagrant.actions.box.verify") @@ -129,6 +139,11 @@ module Vagrant error_key(:virtualbox_not_detected) end + class VMFailedToBoot < VagrantError + status_code(21) + error_key(:failed_to_boot, "vagrant.actions.vm.boot") + end + class VMNotCreatedError < VagrantError status_code(6) error_key(:vm_creation_required) @@ -138,5 +153,10 @@ module Vagrant status_code(4) error_key(:vm_not_found) end + + class VMPowerOffToPackage < VagrantError + status_code(24) + error_key(:power_off, "vagrant.actions.vm.export") + end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index e3b34b883..da0b3427f 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -100,8 +100,18 @@ en: waiting: Waiting for VM to boot. This can take a few minutes. ready: VM booted and ready for use! failed: Failed to connect to VM! + failed_to_boot: VM failed to boot. check_box: not_found: Box %{name} was not found. Fetching box from specified URL... + 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 + using `config.vm.box` + does_not_exist: |- + Specified box `%{name}` does not exist! + + The box must be added through the `vagrant box add` command. Please view + the documentation associated with the command for more information. check_guest_additions: not_detected: |- No guest additions were detected on the base box for this VM! Guest @@ -137,6 +147,7 @@ en: export: create_dir: Creating temporary directory for export... exporting: Exporting VM... + power_off: "The Vagrant virtual environment you are trying to package must be powered off." forward_ports: fixed_collision: Fixed port collision '%{name}'. Now on port %{new_port}. forwarding: Forwarding ports... diff --git a/templates/strings.yml b/templates/strings.yml index 649e720d9..93d471298 100644 --- a/templates/strings.yml +++ b/templates/strings.yml @@ -26,15 +26,6 @@ name you specified and try again. As a reminder, the repackage command is for repackaging boxes which have been added through `vagrant box add` but the box has been lost. -:box_specified_doesnt_exist: |- - Specified box `<%= box_name %>` does not exist! - - The box must be added through the `vagrant box add` command. Please view - the documentation associated with the command for more information. -: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 - using `config.vm.box` :chef_base_invalid_provisioner: |- Vagrant::Provisioners::Chef is not a valid provisioner! Use ChefSolo or ChefServer instead. :chef_server_url_required: |- @@ -123,8 +114,6 @@ :virtualbox_import_failure: |- The VM import failed! Try running `VBoxManage import` on the box file manually for more verbose error output. -:vm_failed_to_boot: |- - Failed to connect to VM! Failed to boot? :vm_port_auto_empty: |- Vagrant found a port collision for the specified port and virtual machine. While this port was marked to be auto-corrected, the ports in the @@ -147,8 +136,6 @@ port. Example, where '1234' would be replaced by a unique host port: config.vm.forward_port("<%= name %>", <%= guestport %>, 1234) -:vm_power_off_to_package: |- - The vagrant virtual environment you are trying to package must be powered off. :vm_mount_fail: |- Failed to mount shared folders. vboxsf was not available. #--------------------------------------------------------------------- diff --git a/test/vagrant/action/vm/boot_test.rb b/test/vagrant/action/vm/boot_test.rb index ebfd87b5f..8a7baf0b7 100644 --- a/test/vagrant/action/vm/boot_test.rb +++ b/test/vagrant/action/vm/boot_test.rb @@ -16,14 +16,6 @@ class BootVMActionTest < Test::Unit::TestCase end context "calling" do - should "do nothing if environment is erroneous" do - @env.error!(:foo) - @instance.expects(:boot).never - @app.expects(:call).never - - @instance.call(@env) - end - should "run the proper methods on success" do boot_seq = sequence("boot_seq") @instance.expects(:boot).in_sequence(boot_seq) @@ -37,18 +29,9 @@ class BootVMActionTest < Test::Unit::TestCase @instance.expects(:boot).in_sequence(boot_seq) @instance.expects(:wait_for_boot).returns(false).in_sequence(boot_seq) @app.expects(:call).never - @instance.call(@env) - end - - should "not continue chain if error occured" do - boot_seq = sequence("boot_seq") - @instance.expects(:boot).in_sequence(boot_seq) - @instance.expects(:wait_for_boot).returns(true).in_sequence(boot_seq).with() do - @env.error!(:interrupt) - true - end - @app.expects(:call).never - @instance.call(@env) + assert_raises(Vagrant::Errors::VMFailedToBoot) { + @instance.call(@env) + } end end diff --git a/test/vagrant/action/vm/check_box_test.rb b/test/vagrant/action/vm/check_box_test.rb index 0e080be22..00bdc3ffa 100644 --- a/test/vagrant/action/vm/check_box_test.rb +++ b/test/vagrant/action/vm/check_box_test.rb @@ -12,14 +12,13 @@ class CheckBoxVMActionTest < Test::Unit::TestCase Vagrant::Box.stubs(:find) end - should "return error if box not specified" do + should "raise error if box not specified" do @env.env.config.vm.box = nil - @app.expects(:call).never - @instance.call(@env) - assert @env.error? - assert_equal :box_not_specified, @env.error.first + assert_raises(Vagrant::Errors::BoxNotSpecified) { + @instance.call(@env) + } end should "error if box does not exist and URL not specified" do @@ -27,10 +26,9 @@ class CheckBoxVMActionTest < Test::Unit::TestCase Vagrant::Box.expects(:find).with(@env.env, @env["config"].vm.box).returns(nil) @app.expects(:call).never - @instance.call(@env) - - assert @env.error? - assert_equal :box_specified_doesnt_exist, @env.error.first + assert_raises(Vagrant::Errors::BoxSpecifiedDoesntExist) { + @instance.call(@env) + } end should "attempt to download box and continue if URL specified" do diff --git a/test/vagrant/action/vm/export_test.rb b/test/vagrant/action/vm/export_test.rb index c1822d5d7..1560159ea 100644 --- a/test/vagrant/action/vm/export_test.rb +++ b/test/vagrant/action/vm/export_test.rb @@ -36,9 +36,9 @@ class ExportVMActionTest < Test::Unit::TestCase @app.expects(:call).with(@env).never @instance.expects(:recover).never - @instance.call(@env) - assert @env.error? - assert_equal :vm_power_off_to_package, @env.error.first + assert_raises(Vagrant::Errors::VMPowerOffToPackage) { + @instance.call(@env) + } end end