If an "ActionException" is raised from an action, the runner will error and exit rather than continuing to raise the exception.
This commit is contained in:
parent
37393986e3
commit
dce3c032be
|
@ -4,6 +4,8 @@ module Vagrant
|
||||||
# for actions. A runner is simply a class which will execute
|
# for actions. A runner is simply a class which will execute
|
||||||
# actions.
|
# actions.
|
||||||
class Runner
|
class Runner
|
||||||
|
include Vagrant::Util
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# Executes a specific action.
|
# Executes a specific action.
|
||||||
def execute!(action_klass, *args)
|
def execute!(action_klass, *args)
|
||||||
|
@ -50,6 +52,12 @@ module Vagrant
|
||||||
action.rescue(e)
|
action.rescue(e)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If its an ActionException, error and exit the message
|
||||||
|
if e.is_a?(ActionException)
|
||||||
|
error_and_exit(e.message)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
# Finally, reraise the exception
|
# Finally, reraise the exception
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
|
@ -158,7 +158,10 @@ class ActionRunnerTest < Test::Unit::TestCase
|
||||||
context "exceptions" do
|
context "exceptions" do
|
||||||
setup do
|
setup do
|
||||||
@actions = [mock_fake_action, mock_fake_action]
|
@actions = [mock_fake_action, mock_fake_action]
|
||||||
@actions.each { |a| @runner.actions << a }
|
@actions.each do |a|
|
||||||
|
a.stubs(:rescue)
|
||||||
|
@runner.actions << a
|
||||||
|
end
|
||||||
|
|
||||||
@exception = Exception.new
|
@exception = Exception.new
|
||||||
end
|
end
|
||||||
|
@ -169,6 +172,8 @@ class ActionRunnerTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
@actions[0].stubs(:execute!).raises(@exception)
|
@actions[0].stubs(:execute!).raises(@exception)
|
||||||
|
|
||||||
|
@runner.expects(:error_and_exit).never
|
||||||
assert_raises(Exception) { @runner.execute! }
|
assert_raises(Exception) { @runner.execute! }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -178,8 +183,19 @@ class ActionRunnerTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
@actions[0].stubs(:prepare).raises(@exception)
|
@actions[0].stubs(:prepare).raises(@exception)
|
||||||
|
|
||||||
|
@runner.expects(:error_and_exit).never
|
||||||
assert_raises(Exception) { @runner.execute! }
|
assert_raises(Exception) { @runner.execute! }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "call error_and_exit if it is an ActionException" do
|
||||||
|
msg = "Message"
|
||||||
|
@exception = Vagrant::Actions::ActionException.new(msg)
|
||||||
|
@actions[0].stubs(:prepare).raises(@exception)
|
||||||
|
|
||||||
|
@runner.expects(:error_and_exit).with(msg).once
|
||||||
|
@runner.execute!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue