rescue upgraded to handle return values or calls with env errors. added error and exit call/interupt handling

This commit is contained in:
John Bender 2010-07-28 22:19:16 -07:00
parent 4e732631d8
commit 36f0eb8feb
2 changed files with 24 additions and 5 deletions

View File

@ -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)

View File

@ -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