From ba5400b89b9b6003fcf9c38a42720cfb777feab6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 9 Jan 2014 10:13:33 -0800 Subject: [PATCH] core: raise user-friendly errors if capabilities exception in Guest --- lib/vagrant/guest.rb | 4 ++++ test/unit/vagrant/guest_test.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/vagrant/guest.rb b/lib/vagrant/guest.rb index 7883df987..f2667caa6 100644 --- a/lib/vagrant/guest.rb +++ b/lib/vagrant/guest.rb @@ -32,6 +32,10 @@ module Vagrant def detect! guest_name = @machine.config.vm.guest initialize_capabilities!(guest_name, @guests, @capabilities, @machine) + rescue Errors::CapabilityHostExplicitNotDetected => e + raise Errors::GuestExplicitNotDetected, value: e.extra_data[:value] + rescue Errors::CapabilityHostNotDetected + raise Errors::GuestNotDetected end # Returns the specified or detected guest type name. diff --git a/test/unit/vagrant/guest_test.rb b/test/unit/vagrant/guest_test.rb index ffae22a4f..7c9d11373 100644 --- a/test/unit/vagrant/guest_test.rb +++ b/test/unit/vagrant/guest_test.rb @@ -34,6 +34,18 @@ describe Vagrant::Guest do subject.detect! end + + it "raises a user-friendly error if specified guest doesn't exist" do + machine.config.vm.stub(guest: :foo) + + expect { subject.detect! }. + to raise_error(Vagrant::Errors::GuestExplicitNotDetected) + end + + it "raises a user-friendly error if auto-detected guest not found" do + expect { subject.detect! }. + to raise_error(Vagrant::Errors::GuestNotDetected) + end end describe "#name" do