diff --git a/hbase-shell/src/main/ruby/shell/commands.rb b/hbase-shell/src/main/ruby/shell/commands.rb index 72f6eb2..1ca40ed 100644 --- a/hbase-shell/src/main/ruby/shell/commands.rb +++ b/hbase-shell/src/main/ruby/shell/commands.rb @@ -34,11 +34,9 @@ module Shell translate_hbase_exceptions(*args) { send(cmd,*args) } rescue => e rootCause = e - while rootCause != nil && rootCause.respond_to?(:cause) && rootCause.cause != nil - rootCause = rootCause.cause - end + cause = get_cause_message(rootCause) puts - puts "ERROR: #{rootCause}" + puts "ERROR: #{cause}" puts "Backtrace: #{rootCause.backtrace.join("\n ")}" if debug puts puts "Here is some help for this command:" @@ -93,6 +91,26 @@ module Shell rescue org.apache.hadoop.hbase.TableExistsException raise "Table already exists: #{args.first}!" end + + def get_cause_message(cause) + while cause != nil && cause.respond_to?(:cause) && cause.cause != nil + # To be safe, here only AccessDeniedException is considered. In future + # we might support more in more generic approach when possible. + if cause.kind_of?(org.apache.hadoop.hbase.security.AccessDeniedException) + str = java.lang.String.new("#{cause}") + # Error message is merged with stack trace, reference StringUtils.stringifyException + # This is to parse and get the error message from the whole. + strs = str.split("\n") + if strs.size > 0 + str = strs[0] + end + return str + end + cause = cause.cause + end + return cause + end + end end end