diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 73d8c8cd6..4ec04fab1 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -242,5 +242,10 @@ module Vagrant status_code(24) error_key(:power_off, "vagrant.actions.vm.export") end + + class VMSystemError < VagrantError + status_code(39) + error_namespace("vagrant.errors.system") + end end end diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 61830deb8..41c38a62b 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -54,19 +54,15 @@ module Vagrant if system.is_a?(Class) @system = system.new(self) - error_and_exit(:system_invalid_class, :system => system.to_s) unless @system.is_a?(Systems::Base) + raise Errors::VMSystemError.new(:_key => :invalid_class, :system => system.to_s) if !@system.is_a?(Systems::Base) elsif system.is_a?(Symbol) # Hard-coded internal systems mapping = { :linux => Systems::Linux } - if !mapping.has_key?(system) - error_and_exit(:system_unknown_type, :system => system.to_s) - return # for tests - end - + raise Errors::VMSystemError.new(:_key => :unknown_type, :system => system.to_s) if !mapping.has_key?(system) @system = mapping[system].new(self) else - error_and_exit(:system_unspecified) + raise Errors::VMSystemError.new(:unspecified) end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index f5ce9c357..15634afee 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -43,6 +43,18 @@ en: http://vagrantup.com/docs/getting-started/windows. + system: + invalid_class: |- + The specified system does not inherit from `Vagrant::Systems::Base`. The + specified system class must inherit from this class. + + The specified system class was: %{system} + unknown_type: |- + The specified system type is unknown: %{system}. Please change this + to a proper value. + unspecified: |- + A VM system type must be specified! This is done via the `config.vm.system` + configuration value. Please read the documentation online for more information. virtualbox_invalid_ose: |- Vagrant has detected you're using an OSE ("Open Source Edition") of VirtualBox. Vagrant currently doesn't support any of the OSE editions due to slight API diff --git a/templates/strings.yml b/templates/strings.yml deleted file mode 100644 index d4107c9c5..000000000 --- a/templates/strings.yml +++ /dev/null @@ -1,20 +0,0 @@ - -# Using YAMLs Block Literals to preserve new lines -# http://en.wikipedia.org/wiki/YAML#Newlines_preserved -# In short, | means keep new lines, trim whitespace left and right -# The |- does the above, but trims the new line at the end of all text - -#--------------------------------------------------------------------- -# CATEGORY: Error Messages -#--------------------------------------------------------------------- -:system_invalid_class: |- - The specified system does not inherit from `Vagrant::Systems::Base`. The - specified system class must inherit from this class. - - The specified system class was: <%= system %> -:system_unknown_type: |- - The specified system type is unknown: <%= system %>. Please change this - to a proper value. -:system_unspecified: |- - A VM system type must be specified! This is done via the `config.vm.system` - configuration value. Please read the documentation online for more information. diff --git a/test/vagrant/vm_test.rb b/test/vagrant/vm_test.rb index c9af61d14..7ce96ff76 100644 --- a/test/vagrant/vm_test.rb +++ b/test/vagrant/vm_test.rb @@ -73,8 +73,9 @@ class VMTest < Test::Unit::TestCase should "error and exit if system is not specified" do @vm.env.config.vm.system = nil - @vm.expects(:error_and_exit).with(:system_unspecified).once - @vm.load_system! + assert_raises(Vagrant::Errors::VMSystemError) { + @vm.load_system! + } end context "with a class" do @@ -93,8 +94,9 @@ class VMTest < Test::Unit::TestCase should "error and exit if class has invalid parent" do @vm.env.config.vm.system = FakeSystemClass - @vm.expects(:error_and_exit).with(:system_invalid_class, :system => @vm.env.config.vm.system.to_s).once - @vm.load_system! + assert_raises(Vagrant::Errors::VMSystemError) { + @vm.load_system! + } end end @@ -116,8 +118,10 @@ class VMTest < Test::Unit::TestCase should "error and exit with invalid symbol" do @vm.env.config.vm.system = :shall_never_exist - @vm.expects(:error_and_exit).with(:system_unknown_type, :system => @vm.env.config.vm.system.to_s).once - @vm.load_system! + + assert_raises(Vagrant::Errors::VMSystemError) { + @vm.load_system! + } end end end