diff options
-rwxr-xr-x | ag | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -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 |