Gentoo Archives: gentoo-commits

From: "Robin H. Johnson" <robbat2@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/ag:master commit in: /
Date: Wed, 25 Feb 2015 23:54:45
Message-Id: 1424908476.face39b1a3a32f3a9a49747059dac1484025458d.robbat2@gentoo
1 commit: face39b1a3a32f3a9a49747059dac1484025458d
2 Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
3 AuthorDate: Wed Feb 25 23:54:36 2015 +0000
4 Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
5 CommitDate: Wed Feb 25 23:54:36 2015 +0000
6 URL: http://sources.gentoo.org/gitweb/?p=proj/ag.git;a=commit;h=face39b1
7
8 Improve error handling.
9
10 Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
11
12 ---
13 ag | 19 ++++++++++++-------
14 1 file changed, 12 insertions(+), 7 deletions(-)
15
16 diff --git a/ag b/ag
17 index f3c106e..5602df5 100755
18 --- a/ag
19 +++ b/ag
20 @@ -51,14 +51,14 @@ op = OptionParser.new do |opts|
21
22 $options.action = :do_delete_msg
23 end
24 -
25 +
26 opts.on('--create-index', 'Create index but do not populate. Needs --list') do
27 abort 'Can only select one action' if $options.action != nil
28
29 $options.action = :do_create_index
30 $options.need_argument = false
31 end
32 -
33 +
34 opts.on('--rethread', 'Rethread messages. Needs --list') do
35 abort 'Can only select one action' if $options.action != nil
36
37 @@ -215,22 +215,27 @@ def do_delete_msg
38 end
39 end
40
41 -def do_delete_index(ignore_missing: false)
42 +def do_delete_index(ignore_missing: false, _raise: false)
43 begin
44 Ag::Storage.delete_index($options.name)
45 rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
46 - $stderr.puts "Index does not exist: #{e}" unless ignore_missing
47 + unless ignore_missing
48 + raise e if _raise
49 + $stderr.puts "Index does not exist: #{e}"
50 + end
51 rescue => e
52 + raise e if _raise
53 $stderr.puts "Cannot delete index: #{e}"
54 end
55 end
56
57 -def do_create_index(ignore_exists: false)
58 +def do_create_index(ignore_exists: false, _raise: false)
59 begin
60 Ag::Storage.create_index($options.name)
61 rescue Elasticsearch::Transport::Transport::Errors::BadRequest => e
62 - if ignore_exists and e !~ /IndexAlreadyExistsException/
63 - raise e
64 + unless (ignore_exists and e.message =~ /IndexAlreadyExistsException/)
65 + raise e if _raise
66 + $stderr.puts "Cannot create index #{e}"
67 end
68 end
69 end