kernel/v2: capture error if provider config is bad [GH-2959]
This commit is contained in:
parent
dd9dd5127c
commit
12b2572687
|
@ -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!
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue