kernel/v2: capture error if provider config is bad [GH-2959]

This commit is contained in:
Mitchell Hashimoto 2014-02-11 11:54:52 -08:00
parent dd9dd5127c
commit 12b2572687
2 changed files with 36 additions and 2 deletions

View File

@ -371,8 +371,14 @@ module VagrantPlugins
# Load it up
config = config_class.new
blocks.each do |b|
b.call(config, Vagrant::Config::V2::DummyConfig.new)
begin
blocks.each do |b|
b.call(config, Vagrant::Config::V2::DummyConfig.new)
end
rescue Exception => e
raise Vagrant::Errors::VagrantfileLoadError,
path: "<provider config: #{name}>",
message: e.message
end
config.finalize!

View File

@ -114,6 +114,34 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
end
end
describe "#provider and #get_provider_config" do
it "compiles the configurations for a provider" do
subject.provider "virtualbox" do |vb|
vb.gui = true
end
subject.provider "virtualbox" do |vb|
vb.name = "foo"
end
subject.finalize!
config = subject.get_provider_config(:virtualbox)
expect(config.name).to eq("foo")
expect(config.gui).to be_true
end
it "raises an exception if there is a problem loading" do
subject.provider "virtualbox" do |vb|
# Purposeful bad variable
vm.foo = "bar"
end
expect { subject.finalize! }.
to raise_error(Vagrant::Errors::VagrantfileLoadError)
end
end
describe "#provision" do
it "stores the provisioners" do
subject.provision("shell", inline: "foo")