public
Description: Remote multi-server automation tool
Homepage: http://www.capify.org
Clone URL: git://github.com/jamis/capistrano.git
Search Repo:
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
jamis (author)
Tue Mar 27 14:41:55 -0700 2007
commit  4331e3bb673f0a5f1f3710c3ee43fb7694a6a9a1
tree    067607682a99e7e2d614f9d86f91c0f9ab75a86c
parent  0b42b7ee877cc6491b5920464e6a8724a69e27d6
...
51
52
53
54
55
 
 
 
 
 
56
57
58
...
51
52
53
 
 
54
55
56
57
58
59
60
61
0
@@ -51,8 +51,11 @@ module Capistrano
0
 
0
       logger.trace "command finished" if logger
0
 
0
- if failed = @channels.detect { |ch| ch[:status] != 0 }
0
- raise CommandError, "command #{command.inspect} failed on #{failed[:host]}"
0
+ if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
0
+ hosts = failed.map { |ch| ch[:host] }
0
+ error = CommandError.new("command #{command.inspect} failed on #{hosts.join(',')}")
0
+ error.hosts = hosts
0
+ raise error
0
       end
0
 
0
       self
...
2
3
4
5
6
7
8
 
 
 
 
9
10
...
2
3
4
 
5
6
7
8
9
10
11
12
13
0
@@ -2,8 +2,11 @@ module Capistrano
0
   class Error < RuntimeError; end
0
 
0
   class CaptureError < Error; end
0
- class CommandError < Error; end
0
   class ConnectionError < Error; end
0
   class UploadError < Error; end
0
   class NoSuchTaskError < Error; end
0
+
0
+ class CommandError < Error
0
+ attr_accessor :hosts
0
+ end
0
 end
0
\ No newline at end of file
...
166
167
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
170
171
...
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
0
@@ -166,6 +166,21 @@ class CommandTest < Test::Unit::TestCase
0
     assert_raises(Capistrano::CommandError) { cmd.process! }
0
   end
0
 
0
+ def test_command_error_should_include_accessor_with_host_array
0
+ sessions = [mock("session", :open_channel => new_channel(true, 0)),
0
+ mock("session", :open_channel => new_channel(true, 0)),
0
+ mock("session", :open_channel => new_channel(true, 1))]
0
+ cmd = Capistrano::Command.new("ls", sessions)
0
+
0
+ begin
0
+ cmd.process!
0
+ flunk "expected an exception to be raised"
0
+ rescue Capistrano::CommandError => e
0
+ assert e.respond_to?(:hosts)
0
+ assert_equal %w(capistrano), e.hosts
0
+ end
0
+ end
0
+
0
   def test_process_should_loop_until_all_channels_are_closed
0
     new_channel = Proc.new do |times|
0
       ch = mock("channel")

Comments

    No one has commented yet.