From 1bf70fd4c49061333a409df502e15cef464d06bc Mon Sep 17 00:00:00 2001 From: Ewen Cheslack-Postava Date: Tue, 9 Mar 2010 22:00:56 -0800 Subject: [PATCH] Show helpful error if importing VM fails --- lib/vagrant/actions/vm/import.rb | 1 + test/vagrant/actions/vm/import_test.rb | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/actions/vm/import.rb b/lib/vagrant/actions/vm/import.rb index 56a8e8d2e..3dcf72729 100644 --- a/lib/vagrant/actions/vm/import.rb +++ b/lib/vagrant/actions/vm/import.rb @@ -8,6 +8,7 @@ module Vagrant logger.info "Importing base VM (#{Vagrant::Env.box.ovf_file})..." # Use the first argument passed to the action @runner.vm = VirtualBox::VM.import(Vagrant::Env.box.ovf_file) + raise ActionException.new("The VM import failed! Try running `VBoxManage import` on the box file manually for more verbose error output.") unless @runner.vm end end end diff --git a/test/vagrant/actions/vm/import_test.rb b/test/vagrant/actions/vm/import_test.rb index 451aaabe3..5416e0968 100644 --- a/test/vagrant/actions/vm/import_test.rb +++ b/test/vagrant/actions/vm/import_test.rb @@ -23,14 +23,21 @@ class ImportActionTest < Test::Unit::TestCase end should "call import on VirtualBox::VM with the proper base" do - VirtualBox::VM.expects(:import).once.with(@ovf_file) - @import.execute! + VirtualBox::VM.expects(:import).once.with(@ovf_file).returns("foo") + assert_nothing_raised { @import.execute! } + end + + should "raise an exception if import is nil" do + @mock_vm.expects(:vm).returns(nil) + assert_raises(Vagrant::Actions::ActionException) { + @import.execute! + } end should "set the resulting VM as the VM of the Vagrant VM object" do new_vm = mock("new_vm") @mock_vm.expects(:vm=).with(new_vm).once - VirtualBox::VM.expects(:import).returns(new_vm) + VirtualBox::VM.expects(:import).returns(new_vm).returns("foo") @import.execute! end end