diff --git a/hbase-shell/src/main/ruby/shell/commands.rb b/hbase-shell/src/main/ruby/shell/commands.rb index 2128164ed04..2abccddf045 100644 --- a/hbase-shell/src/main/ruby/shell/commands.rb +++ b/hbase-shell/src/main/ruby/shell/commands.rb @@ -102,9 +102,13 @@ module Shell # Get the special java exception which will be handled cause = e.cause + # let individual command handle exceptions first + if self.respond_to?(:handle_exceptions) + self.handle_exceptions(cause, *args) + end + # Global HBase exception handling below if not handled by respective command above if cause.kind_of?(org.apache.hadoop.hbase.TableNotFoundException) then - str = java.lang.String.new("#{cause}") - raise "Unknown table #{str}!" + raise "Unknown table #{args.first}!" end if cause.kind_of?(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) then exceptions = cause.getCauses @@ -116,15 +120,7 @@ module Shell end end if cause.kind_of?(org.apache.hadoop.hbase.TableExistsException) then - str = java.lang.String.new("#{cause}") - strs = str.split("\n") - if strs.size > 0 then - s = strs[0].split(' '); - if(s.size > 1) - raise "Table already exists: #{s[1]}!" - end - raise "Table already exists: #{strs[0]}!" - end + raise "Table already exists: #{args.first}!" end # To be safe, here only AccessDeniedException is considered. In future # we might support more in more generic approach when possible. diff --git a/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb b/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb index 8c193bb7c10..0498c8e3e4f 100644 --- a/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb +++ b/hbase-shell/src/main/ruby/shell/commands/clone_snapshot.rb @@ -36,6 +36,13 @@ EOF admin.clone_snapshot(snapshot_name, table) end end + + def handle_exceptions(cause, *args) + if cause.kind_of?(org.apache.hadoop.hbase.TableExistsException) then + tableName = args[1] + raise "Table already exists: #{tableName}!" + end + end end end end