diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index 219575536..047a48d2a 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -148,9 +148,9 @@ module Vagrant # the command completes. This is an almost line for line copy of # the actual `exec!` implementation, except that this # implementation also reports `:exit_status` to the block if given. - def exec!(command, &block) + def exec!(command, options=nil, &block) block ||= Proc.new do |ch, type, data| - check_exit_status(data, command) if type == :exit_status + check_exit_status(data, command, options) if type == :exit_status ch[:result] ||= "" ch[:result] << data if [:stdout, :stderr].include?(type) @@ -183,9 +183,16 @@ module Vagrant # Checks for an erroroneous exit status and raises an exception # if so. - def check_exit_status(exit_status, command) + def check_exit_status(exit_status, command, options=nil) if exit_status != 0 - raise Actions::ActionException.new(:ssh_bad_exit_status, :command => command) + options = { + :error_key => :ssh_bad_exit_status, + :error_data => { + :command => command + } + }.merge(options || {}) + + raise Actions::ActionException.new(options[:error_key], options[:error_data]) end end end diff --git a/test/vagrant/ssh_session_test.rb b/test/vagrant/ssh_session_test.rb index 68ee0d385..2bdb50ca3 100644 --- a/test/vagrant/ssh_session_test.rb +++ b/test/vagrant/ssh_session_test.rb @@ -15,6 +15,19 @@ class SshTest < Test::Unit::TestCase } end + should "raise the given exception if specified" do + options = { + :error_key => :foo, + :error_data => {} + } + result = Exception.new + Vagrant::Actions::ActionException.expects(:new).with(options[:error_key], options[:error_data]).once.returns(result) + + assert_raises(Exception) { + @instance.check_exit_status(1, "foo", options) + } + end + should "raise nothing if its zero" do assert_nothing_raised { @instance.check_exit_status(0, "foo")