rescue upgraded to handle return values or calls with env errors. added error and exit call/interupt handling
This commit is contained in:
parent
4e732631d8
commit
36f0eb8feb
|
@ -1,6 +1,7 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
class Action
|
class Action
|
||||||
class Warden
|
class Warden
|
||||||
|
include Util
|
||||||
attr_accessor :actions, :stack
|
attr_accessor :actions, :stack
|
||||||
|
|
||||||
def initialize(actions, env)
|
def initialize(actions, env)
|
||||||
|
@ -11,17 +12,22 @@ module Vagrant
|
||||||
def call(env)
|
def call(env)
|
||||||
return if @actions.empty?
|
return if @actions.empty?
|
||||||
|
|
||||||
if env.error?
|
# If the previous action passes and environment error on
|
||||||
begin_rescue(env)
|
@stack.push(@actions.pop).last.call(env) unless env.error?
|
||||||
else
|
|
||||||
@stack.push(@actions.pop).last.call(env)
|
# if the call action returned prematurely with an error
|
||||||
end
|
begin_rescue(env) if env.error?
|
||||||
end
|
end
|
||||||
|
|
||||||
def begin_rescue(env)
|
def begin_rescue(env)
|
||||||
@stack.reverse.each do |act|
|
@stack.reverse.each do |act|
|
||||||
act.rescue(env) if act.respond_to?(:rescue)
|
act.rescue(env) if act.respond_to?(:rescue)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
exit if env.interrupted?
|
||||||
|
|
||||||
|
# Erroneous environment resulted. Properly display error message.
|
||||||
|
error_and_exit(*env.error)
|
||||||
end
|
end
|
||||||
|
|
||||||
def finalize_action(action, env)
|
def finalize_action(action, env)
|
||||||
|
|
|
@ -4,6 +4,7 @@ class ActionWardenTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@klass = Vagrant::Action::Warden
|
@klass = Vagrant::Action::Warden
|
||||||
@instance = @klass.new([], {})
|
@instance = @klass.new([], {})
|
||||||
|
@klass.any_instance.stubs(:error_and_exit)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "initializing" do
|
context "initializing" do
|
||||||
|
@ -84,6 +85,18 @@ class ActionWardenTest < Test::Unit::TestCase
|
||||||
|
|
||||||
@instance.begin_rescue(new_env)
|
@instance.begin_rescue(new_env)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def new_env
|
def new_env
|
||||||
|
|
Loading…
Reference in New Issue