HBASE-26880 Misspelling commands in hbase shell will crash the shell (#4325)
Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
parent
e7eb628025
commit
d001fb00f4
|
@ -23,7 +23,7 @@ module IRB
|
||||||
|
|
||||||
# Subclass of IRB so can intercept methods
|
# Subclass of IRB so can intercept methods
|
||||||
class HIRB < Irb
|
class HIRB < Irb
|
||||||
def initialize(workspace = nil, input_method = nil)
|
def initialize(workspace = nil, interactive = true, input_method = nil)
|
||||||
# This is ugly. Our 'help' method above provokes the following message
|
# This is ugly. Our 'help' method above provokes the following message
|
||||||
# on irb construction: 'irb: warn: can't alias help from irb_help.'
|
# on irb construction: 'irb: warn: can't alias help from irb_help.'
|
||||||
# Below, we reset the output so its pointed at /dev/null during irb
|
# Below, we reset the output so its pointed at /dev/null during irb
|
||||||
|
@ -46,6 +46,7 @@ module IRB
|
||||||
if $stdin.tty?
|
if $stdin.tty?
|
||||||
`stty icrnl <&2`
|
`stty icrnl <&2`
|
||||||
end
|
end
|
||||||
|
@interactive = interactive
|
||||||
super(workspace, input_method)
|
super(workspace, input_method)
|
||||||
ensure
|
ensure
|
||||||
f.close
|
f.close
|
||||||
|
@ -117,11 +118,14 @@ module IRB
|
||||||
rescue Interrupt => exc
|
rescue Interrupt => exc
|
||||||
rescue SystemExit, SignalException
|
rescue SystemExit, SignalException
|
||||||
raise
|
raise
|
||||||
rescue Exception
|
rescue NameError => exc
|
||||||
|
raise exc unless @interactive
|
||||||
|
# HBASE-26880: Ignore NameError to prevent exiting Shell on mistyped commands.
|
||||||
|
rescue Exception => exc
|
||||||
# HBASE-26741: Raise exception so Shell::exception_handler can catch it.
|
# HBASE-26741: Raise exception so Shell::exception_handler can catch it.
|
||||||
# This modifies this copied method from JRuby so that the HBase shell can
|
# This modifies this copied method from JRuby so that the HBase shell can
|
||||||
# manage the exception and set a proper exit code on the process.
|
# manage the exception and set a proper exit code on the process.
|
||||||
raise
|
raise exc
|
||||||
end
|
end
|
||||||
if exc
|
if exc
|
||||||
if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
|
if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
|
||||||
|
|
|
@ -213,7 +213,7 @@ workspace = @shell.get_workspace
|
||||||
# script calls 'exit' or 'exit 0' or 'exit errcode'.
|
# script calls 'exit' or 'exit 0' or 'exit errcode'.
|
||||||
if script2run
|
if script2run
|
||||||
::Shell::Shell.exception_handler(!full_backtrace) do
|
::Shell::Shell.exception_handler(!full_backtrace) do
|
||||||
IRB::HIRB.new(workspace, IRB::HBaseLoader.file_for_load(script2run)).run
|
IRB::HIRB.new(workspace, interactive, IRB::HBaseLoader.file_for_load(script2run)).run
|
||||||
end
|
end
|
||||||
exit @shell.exit_code unless @shell.exit_code.nil?
|
exit @shell.exit_code unless @shell.exit_code.nil?
|
||||||
end
|
end
|
||||||
|
@ -222,5 +222,5 @@ if interactive
|
||||||
# Output a banner message that tells users where to go for help
|
# Output a banner message that tells users where to go for help
|
||||||
@shell.print_banner
|
@shell.print_banner
|
||||||
end
|
end
|
||||||
IRB::HIRB.new(workspace).run
|
IRB::HIRB.new(workspace, interactive).run
|
||||||
exit @shell.exit_code unless interactive || @shell.exit_code.nil?
|
exit @shell.exit_code unless interactive || @shell.exit_code.nil?
|
||||||
|
|
Loading…
Reference in New Issue