HBASE-9570 With AccessDeniedException, HBase shell would be better to just display the error message to be user friendly (Yang Wang)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1532163 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5f61023e1d
commit
2e5eb8bd0c
|
@ -85,13 +85,35 @@ module Shell
|
||||||
|
|
||||||
def translate_hbase_exceptions(*args)
|
def translate_hbase_exceptions(*args)
|
||||||
yield
|
yield
|
||||||
rescue org.apache.hadoop.hbase.TableNotFoundException
|
rescue => e
|
||||||
raise "Unknown table #{args.first}!"
|
raise e unless e.respond_to?(:cause) && e.cause != nil
|
||||||
rescue org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException
|
|
||||||
valid_cols = table(args.first).get_all_columns.map { |c| c + '*' }
|
# Get the special java exception which will be handled
|
||||||
raise "Unknown column family! Valid column names: #{valid_cols.join(", ")}"
|
cause = e.cause
|
||||||
rescue org.apache.hadoop.hbase.TableExistsException
|
if cause.kind_of?(org.apache.hadoop.hbase.TableNotFoundException) then
|
||||||
raise "Table already exists: #{args.first}!"
|
raise "Unknown table #{args.first}!"
|
||||||
|
end
|
||||||
|
if cause.kind_of?(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException) then
|
||||||
|
valid_cols = table(args.first).get_all_columns.map { |c| c + '*' }
|
||||||
|
raise "Unknown column family! Valid column names: #{valid_cols.join(", ")}"
|
||||||
|
end
|
||||||
|
if cause.kind_of?(org.apache.hadoop.hbase.TableExistsException) then
|
||||||
|
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.
|
||||||
|
if cause.kind_of?(org.apache.hadoop.hbase.security.AccessDeniedException) then
|
||||||
|
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 then
|
||||||
|
raise "#{strs[0]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Throw the other exception which hasn't been handled above
|
||||||
|
raise e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue