Skip to content

Commit 56e3341

Browse files
committed
Simplify exceptions handling
1 parent 150f5e0 commit 56e3341

File tree

14 files changed

+8
-16
lines changed

14 files changed

+8
-16
lines changed

core/src/main/ruby/shell/commands.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(shell)
88
end
99

1010
def command_safe(debug, *args)
11-
command(*args)
11+
translate_hbase_exceptions(*args) { command(*args) }
1212
rescue => e
1313
puts
1414
puts "ERROR: #{e}"
@@ -42,8 +42,13 @@ def format_simple_command
4242
formatter.footer(now)
4343
end
4444

45-
def check_table(table)
46-
raise ArgumentError, "Unknown table #{table}!" unless admin.exists?(table)
45+
def translate_hbase_exceptions(*args)
46+
yield
47+
rescue org.apache.hadoop.hbase.TableNotFoundException
48+
raise "Unknown table #{args.first}!"
49+
rescue org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException
50+
valid_cols = table(args.first).get_all_columns.map { |c| c + '*' }
51+
raise "Unknown column family! Valid column names: #{valid_cols.join(", ")}"
4752
end
4853
end
4954
end

core/src/main/ruby/shell/commands/alter.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def help
2929
end
3030

3131
def command(table, *args)
32-
check_table(table)
3332
format_simple_command do
3433
admin.alter(table, *args)
3534
end

core/src/main/ruby/shell/commands/count.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def help
1414
end
1515

1616
def command(table, interval = 1000)
17-
check_table(table)
1817
now = Time.now
1918
formatter.header
2019
count = table(table).count(interval) do |cnt, row|

core/src/main/ruby/shell/commands/delete.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def help
1414
end
1515

1616
def command(table, row, column, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP)
17-
check_table(table)
1817
format_simple_command do
1918
table(table).delete(row, column, timestamp)
2019
end

core/src/main/ruby/shell/commands/deleteall.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def help
1313
end
1414

1515
def command(table, row, column = nil, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP)
16-
check_table(table)
1716
format_simple_command do
1817
table(table).deleteall(row, column, timestamp)
1918
end

core/src/main/ruby/shell/commands/describe.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def help
99
end
1010

1111
def command(table)
12-
check_table(table)
1312
now = Time.now
1413
desc = admin.describe(table)
1514
formatter.header([ "DESCRIPTION", "ENABLED" ], [ 64 ])

core/src/main/ruby/shell/commands/disable.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ def help
88
end
99

1010
def command(table)
11-
check_table(table)
1211
format_simple_command do
1312
admin.disable(table)
1413
end

core/src/main/ruby/shell/commands/drop.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def help
1111
end
1212

1313
def command(table)
14-
check_table(table)
1514
format_simple_command do
1615
admin.drop(table)
1716
end

core/src/main/ruby/shell/commands/enable.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ def help
88
end
99

1010
def command(table)
11-
check_table(table)
1211
format_simple_command do
1312
admin.enable(table)
1413
end

core/src/main/ruby/shell/commands/exists.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ def help
88
end
99

1010
def command(table)
11-
check_table(table)
1211
format_simple_command do
1312
formatter.row([
1413
"Table #{table} " + (admin.exists?(table.to_s) ? "does exist" : "does not exist")

0 commit comments

Comments
 (0)