commit:     face39b1a3a32f3a9a49747059dac1484025458d
Author:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 25 23:54:36 2015 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Wed Feb 25 23:54:36 2015 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/ag.git;a=commit;h=face39b1

Improve error handling.

Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>

---
 ag | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/ag b/ag
index f3c106e..5602df5 100755
--- a/ag
+++ b/ag
@@ -51,14 +51,14 @@ op = OptionParser.new do |opts|
 
     $options.action = :do_delete_msg
   end
-  
+
   opts.on('--create-index', 'Create index but do not populate. Needs --list') 
do
     abort 'Can only select one action' if $options.action != nil
 
     $options.action = :do_create_index
     $options.need_argument = false
   end
-  
+ 
   opts.on('--rethread', 'Rethread messages. Needs --list') do
     abort 'Can only select one action' if $options.action != nil
 
@@ -215,22 +215,27 @@ def do_delete_msg
   end
 end
 
-def do_delete_index(ignore_missing: false)
+def do_delete_index(ignore_missing: false, _raise: false)
   begin
     Ag::Storage.delete_index($options.name)
   rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
-    $stderr.puts "Index does not exist: #{e}" unless ignore_missing
+    unless ignore_missing
+        raise e if _raise
+        $stderr.puts "Index does not exist: #{e}"
+    end
   rescue => e
+    raise e if _raise
     $stderr.puts "Cannot delete index: #{e}"
   end
 end
 
-def do_create_index(ignore_exists: false)
+def do_create_index(ignore_exists: false, _raise: false)
   begin
     Ag::Storage.create_index($options.name)
   rescue Elasticsearch::Transport::Transport::Errors::BadRequest => e
-    if ignore_exists and e !~ /IndexAlreadyExistsException/
-        raise e
+    unless (ignore_exists and e.message =~ /IndexAlreadyExistsException/)
+        raise e  if _raise
+        $stderr.puts "Cannot create index #{e}"
     end
   end
 end

Reply via email to