From dce3c032be21cf41de57c8fc9b6cff59688017c7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 28 Feb 2010 01:24:11 -0800 Subject: [PATCH] If an "ActionException" is raised from an action, the runner will error and exit rather than continuing to raise the exception. --- lib/vagrant/actions/runner.rb | 8 ++++++++ test/vagrant/actions/runner_test.rb | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/actions/runner.rb b/lib/vagrant/actions/runner.rb index 48bbbfed7..c6b5aa9fb 100644 --- a/lib/vagrant/actions/runner.rb +++ b/lib/vagrant/actions/runner.rb @@ -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 diff --git a/test/vagrant/actions/runner_test.rb b/test/vagrant/actions/runner_test.rb index 451522b2f..f0cebbfe7 100644 --- a/test/vagrant/actions/runner_test.rb +++ b/test/vagrant/actions/runner_test.rb @@ -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