diff --git a/lib/vagrant/action/warden.rb b/lib/vagrant/action/warden.rb index b054a58bd..5303e2a56 100644 --- a/lib/vagrant/action/warden.rb +++ b/lib/vagrant/action/warden.rb @@ -1,6 +1,7 @@ module Vagrant class Action class Warden + include Util attr_accessor :actions, :stack def initialize(actions, env) @@ -11,17 +12,22 @@ module Vagrant def call(env) return if @actions.empty? - if env.error? - begin_rescue(env) - else - @stack.push(@actions.pop).last.call(env) - end + # If the previous action passes and environment error on + @stack.push(@actions.pop).last.call(env) unless env.error? + + # if the call action returned prematurely with an error + begin_rescue(env) if env.error? end def begin_rescue(env) @stack.reverse.each do |act| act.rescue(env) if act.respond_to?(:rescue) end + + exit if env.interrupted? + + # Erroneous environment resulted. Properly display error message. + error_and_exit(*env.error) end def finalize_action(action, env) diff --git a/test/vagrant/action/warden_test.rb b/test/vagrant/action/warden_test.rb index f4f63a15c..05a4c33f5 100644 --- a/test/vagrant/action/warden_test.rb +++ b/test/vagrant/action/warden_test.rb @@ -4,6 +4,7 @@ class ActionWardenTest < Test::Unit::TestCase setup do @klass = Vagrant::Action::Warden @instance = @klass.new([], {}) + @klass.any_instance.stubs(:error_and_exit) end context "initializing" do @@ -84,6 +85,18 @@ class ActionWardenTest < Test::Unit::TestCase @instance.begin_rescue(new_env) end + + should "call error and exit" do + @instance.expects(:error_and_exit) + @instance.begin_rescue(new_env) + end + + should "call exit if the environment is interupted" do + @instance.expects(:exit) + env = new_env + env.expects(:interrupted?).returns(true) + @instance.begin_rescue(env) + end end def new_env