diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2015-02-25 15:54:36 -0800 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2015-02-25 15:54:36 -0800 |
commit | face39b1a3a32f3a9a49747059dac1484025458d (patch) | |
tree | 4bb9a21ba47f8ad2882c100d7ba98a13a1073723 /ag | |
parent | Refactor to simplify for a quick bug I hit. (diff) | |
download | backend-face39b1a3a32f3a9a49747059dac1484025458d.tar.gz backend-face39b1a3a32f3a9a49747059dac1484025458d.tar.bz2 backend-face39b1a3a32f3a9a49747059dac1484025458d.zip |
Improve error handling.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'ag')
-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 |