mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
make CommandError able to report on which hosts failed
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6482 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
0b42b7ee87
commit
4331e3bb67
3 changed files with 24 additions and 3 deletions
|
@ -51,8 +51,11 @@ module Capistrano
|
|||
|
||||
logger.trace "command finished" if logger
|
||||
|
||||
if failed = @channels.detect { |ch| ch[:status] != 0 }
|
||||
raise CommandError, "command #{command.inspect} failed on #{failed[:host]}"
|
||||
if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
|
||||
hosts = failed.map { |ch| ch[:host] }
|
||||
error = CommandError.new("command #{command.inspect} failed on #{hosts.join(',')}")
|
||||
error.hosts = hosts
|
||||
raise error
|
||||
end
|
||||
|
||||
self
|
||||
|
|
|
@ -2,8 +2,11 @@ module Capistrano
|
|||
class Error < RuntimeError; end
|
||||
|
||||
class CaptureError < Error; end
|
||||
class CommandError < Error; end
|
||||
class ConnectionError < Error; end
|
||||
class UploadError < Error; end
|
||||
class NoSuchTaskError < Error; end
|
||||
|
||||
class CommandError < Error
|
||||
attr_accessor :hosts
|
||||
end
|
||||
end
|
|
@ -166,6 +166,21 @@ class CommandTest < Test::Unit::TestCase
|
|||
assert_raises(Capistrano::CommandError) { cmd.process! }
|
||||
end
|
||||
|
||||
def test_command_error_should_include_accessor_with_host_array
|
||||
sessions = [mock("session", :open_channel => new_channel(true, 0)),
|
||||
mock("session", :open_channel => new_channel(true, 0)),
|
||||
mock("session", :open_channel => new_channel(true, 1))]
|
||||
cmd = Capistrano::Command.new("ls", sessions)
|
||||
|
||||
begin
|
||||
cmd.process!
|
||||
flunk "expected an exception to be raised"
|
||||
rescue Capistrano::CommandError => e
|
||||
assert e.respond_to?(:hosts)
|
||||
assert_equal %w(capistrano), e.hosts
|
||||
end
|
||||
end
|
||||
|
||||
def test_process_should_loop_until_all_channels_are_closed
|
||||
new_channel = Proc.new do |times|
|
||||
ch = mock("channel")
|
||||
|
|
Loading…
Reference in a new issue