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:
Mitchell Hashimoto 2010-02-28 01:24:11 -08:00
parent 37393986e3
commit dce3c032be
2 changed files with 25 additions and 1 deletions

View File

@ -4,6 +4,8 @@ module Vagrant
# for actions. A runner is simply a class which will execute
# actions.
class Runner
include Vagrant::Util
class << self
# Executes a specific action.
def execute!(action_klass, *args)
@ -50,6 +52,12 @@ module Vagrant
action.rescue(e)
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
raise
end

View File

@ -158,7 +158,10 @@ class ActionRunnerTest < Test::Unit::TestCase
context "exceptions" do
setup do
@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
end
@ -169,6 +172,8 @@ class ActionRunnerTest < Test::Unit::TestCase
end
@actions[0].stubs(:execute!).raises(@exception)
@runner.expects(:error_and_exit).never
assert_raises(Exception) { @runner.execute! }
end
@ -178,8 +183,19 @@ class ActionRunnerTest < Test::Unit::TestCase
end
@actions[0].stubs(:prepare).raises(@exception)
@runner.expects(:error_and_exit).never
assert_raises(Exception) { @runner.execute! }
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