Skip to content

Commit

Permalink
Make the "no matching servers" error more sane (closes #8828)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@7205 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jamis committed Jul 21, 2007
1 parent f77c785 commit 4e64823
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Make the "no matching servers" error more sane [halorgium]

* Make sure the invoke task gives a sane error when the COMMAND value is omitted [halorgium]

* Make sure variables are conditionally set in the deploy recipes, so as not to clobber values set elsewhere [Jamis Buck]
Expand Down
4 changes: 2 additions & 2 deletions lib/capistrano/configuration/connections.rb
Expand Up @@ -105,7 +105,7 @@ def execute_on_servers(options={})
servers = find_servers_for_task(task, options)

if servers.empty?
raise ScriptError, "`#{task.fully_qualified_name}' is only run for servers matching #{task.options.inspect}, but no servers matched"
raise Capistrano::NoMatchingServersError, "`#{task.fully_qualified_name}' is only run for servers matching #{task.options.inspect}, but no servers matched"
end

if task.continue_on_error?
Expand All @@ -114,7 +114,7 @@ def execute_on_servers(options={})
end
else
servers = find_servers(options)
raise ScriptError, "no servers found to match #{options.inspect}" if servers.empty?
raise Capistrano::NoMatchingServersError, "no servers found to match #{options.inspect}" if servers.empty?
end

servers = [servers.first] if options[:once]
Expand Down
1 change: 1 addition & 0 deletions lib/capistrano/errors.rb
Expand Up @@ -3,6 +3,7 @@ class Error < RuntimeError; end

class CaptureError < Error; end
class NoSuchTaskError < Error; end
class NoMatchingServersError < Error; end

class RemoteError < Error
attr_accessor :hosts
Expand Down
2 changes: 1 addition & 1 deletion lib/capistrano/shell.rb
Expand Up @@ -160,7 +160,7 @@ def exec_tasks(list)
connect(task)
configuration.execute_task(task)
end
rescue Capistrano::NoSuchTaskError => error
rescue Capistrano::NoMatchingServersError, Capistrano::NoSuchTaskError => error
warn "error: #{error.message}"
end

Expand Down
10 changes: 6 additions & 4 deletions lib/capistrano/task_definition.rb
Expand Up @@ -3,14 +3,16 @@
module Capistrano
# Represents the definition of a single task.
class TaskDefinition
attr_reader :name, :namespace, :options, :body
attr_reader :name, :namespace, :options, :body, :desc, :on_error

def initialize(name, namespace, options={}, &block)
@name, @namespace, @options = name, namespace, options
@desc = @options.delete(:desc)
@on_error = options.delete(:on_error)
@body = block or raise ArgumentError, "a task requires a block"
@servers = nil
end

# Returns the task's fully-qualified name, including the namespace
def fully_qualified_name
@fully_qualified_name ||= begin
Expand All @@ -28,7 +30,7 @@ def fully_qualified_name
def description(rebuild=false)
@description = nil if rebuild
@description ||= begin
description = options[:desc] || ""
description = @desc || ""

indentation = description[/\A\s+/]
if indentation
Expand Down Expand Up @@ -61,7 +63,7 @@ def brief_description(max_length=nil)
# Indicates whether the task wants to continue, even if a server has failed
# previously
def continue_on_error?
options[:on_error] == :continue
@on_error == :continue
end
end
end
4 changes: 2 additions & 2 deletions test/configuration/connections_test.rb
Expand Up @@ -138,13 +138,13 @@ def test_execute_on_servers_without_current_task_should_call_find_servers

def test_execute_on_servers_without_current_task_should_raise_error_if_no_matching_servers
@config.expects(:find_servers).with(:a => :b, :c => :d).returns([])
assert_raises(ScriptError) { @config.execute_on_servers(:a => :b, :c => :d) { |list| } }
assert_raises(Capistrano::NoMatchingServersError) { @config.execute_on_servers(:a => :b, :c => :d) { |list| } }
end

def test_execute_on_servers_should_raise_an_error_if_the_current_task_has_no_matching_servers_by_default
@config.current_task = mock_task
@config.expects(:find_servers_for_task).with(@config.current_task, {}).returns([])
assert_raises(ScriptError) do
assert_raises(Capistrano::NoMatchingServersError) do
@config.execute_on_servers do
flunk "should not get here"
end
Expand Down
6 changes: 3 additions & 3 deletions test/configuration/namespace_dsl_test.rb
Expand Up @@ -58,14 +58,14 @@ def test_pending_desc_should_apply_only_to_immediately_subsequent_task
@config.desc "A description"
@config.task(:testing) { puts "foo" }
@config.task(:another) { puts "bar" }
assert_equal "A description", @config.tasks[:testing].options[:desc]
assert_nil @config.tasks[:another].options[:desc]
assert_equal "A description", @config.tasks[:testing].desc
assert_nil @config.tasks[:another].desc
end

def test_pending_desc_should_apply_only_to_next_task_in_any_namespace
@config.desc "A description"
@config.namespace(:outer) { task(:testing) { puts "foo" } }
assert_equal "A description", @config.namespaces[:outer].tasks[:testing].options[:desc]
assert_equal "A description", @config.namespaces[:outer].tasks[:testing].desc
end

def test_defining_task_without_block_should_raise_error
Expand Down

0 comments on commit 4e64823

Please sign in to comment.