Convert VM errors to I18n exceptions

This commit is contained in:
Mitchell Hashimoto 2010-09-01 14:26:53 -07:00
parent f708bf65a7
commit bb97b388f9
5 changed files with 30 additions and 33 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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