From b251d9b95409f3bac3906100f878c1248d9edf22 Mon Sep 17 00:00:00 2001 From: John Bender Date: Sun, 25 Jul 2010 21:59:56 -0700 Subject: [PATCH] begin rescue added --- lib/vagrant/action/warden.rb | 13 ++++++++++++- test/vagrant/action/warden_test.rb | 12 ++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/vagrant/action/warden.rb b/lib/vagrant/action/warden.rb index aa13afce5..a380eeb09 100644 --- a/lib/vagrant/action/warden.rb +++ b/lib/vagrant/action/warden.rb @@ -10,7 +10,18 @@ module Vagrant def call(env) return if @actions.empty? - @stack.push(@actions.pop).last.call(env) + + if env.error? + begin_rescue(env) + else + @stack.push(@actions.pop).last.call(env) + end + end + + def begin_rescue(env) + @stack.reverse.each do |action| + action.rescue(env) if actions.respond_to?(:rescue) + end end def finalize_action(action, env) diff --git a/test/vagrant/action/warden_test.rb b/test/vagrant/action/warden_test.rb index 41e5e79f0..b3629e371 100644 --- a/test/vagrant/action/warden_test.rb +++ b/test/vagrant/action/warden_test.rb @@ -12,7 +12,7 @@ class ActionWardenTest < Test::Unit::TestCase middleware.each do |m| @klass.any_instance.expects(:finalize_action).with(m, {}).returns(m) end - @warden = @klass.new(middleware, {}) + @warden = @klass.new(middleware, new_env) assert_equal @warden.actions, [3,2,1] end end @@ -36,13 +36,13 @@ class ActionWardenTest < Test::Unit::TestCase context "calling" do should "return if there are no actions to execute" do @instance.actions.expects(:pop).never - assert !@instance.call({}) + assert !@instance.call(new_env) end should "move the last action to the front of the stack" do @instance.actions << lambda {} assert @instance.stack.empty? - @instance.call({}) + @instance.call(new_env) assert !@instance.stack.empty? assert @instance.actions.empty? end @@ -51,7 +51,11 @@ class ActionWardenTest < Test::Unit::TestCase action = mock('action') action.expects(:call).with({}) @instance.actions << action - @instance.call({}) + @instance.call(new_env) end end + + def new_env + Vagrant::Action::Environment.new(nil) + end end