From 89b1a46ebf71d862fe496cd561d91d9d62bb524e Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sat, 23 Dec 2006 22:59:50 +0000 Subject: [PATCH] cleaner error messages for authentication failures and command errors (closes #6374) git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@5775 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- CHANGELOG | 2 ++ lib/capistrano/cli.rb | 12 ++++++++++++ lib/capistrano/command.rb | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 9d28762a..1473d73b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Cleaner error messages for authentication failures and command errors + * Added support for ~/.caprc, also -x and -c switches. * Updated migrate action to use db:migrate task in Rails instead of the deprecated migrate task [DHH] diff --git a/lib/capistrano/cli.rb b/lib/capistrano/cli.rb index 81adbf49..67b40546 100644 --- a/lib/capistrano/cli.rb +++ b/lib/capistrano/cli.rb @@ -269,6 +269,8 @@ DETAIL actor = config.actor options[:actions].each { |action| actor.send action } + rescue Exception => error + handle_error(error) end # Load the Rails generator and apply it to the specified directory. @@ -325,5 +327,15 @@ DETAIL def look_for_raw_actions! @options[:actions].concat(@args) end + + def handle_error(error) + case error + when Net::SSH::AuthenticationFailed + abort "authentication failed for `#{error.message}'" + when Capistrano::Command::Error + abort(error.message) + else raise error + end + end end end diff --git a/lib/capistrano/command.rb b/lib/capistrano/command.rb index 06e8ddfc..720dff98 100644 --- a/lib/capistrano/command.rb +++ b/lib/capistrano/command.rb @@ -3,6 +3,8 @@ module Capistrano # This class encapsulates a single command to be executed on a set of remote # machines, in parallel. class Command + class Error < RuntimeError; end + attr_reader :servers, :command, :options, :actor def initialize(servers, command, callback, options, actor) #:nodoc: @@ -42,7 +44,7 @@ module Capistrano logger.trace "command finished" if failed = @channels.detect { |ch| ch[:status] != 0 } - raise "command #{@command.inspect} failed on #{failed[:host]}" + raise Error, "command #{@command.inspect} failed on #{failed[:host]}" end self