Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-26880 Misspelling commands in hbase shell will crash the shell #4325

Merged
merged 2 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions hbase-shell/src/main/ruby/irb/hirb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module IRB

# Subclass of IRB so can intercept methods
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
# 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
Expand All @@ -46,6 +46,7 @@ def initialize(workspace = nil, input_method = nil)
if $stdin.tty?
`stty icrnl <&2`
end
@interactive = interactive
super(workspace, input_method)
ensure
f.close
Expand Down Expand Up @@ -117,11 +118,14 @@ def eval_input
rescue Interrupt => exc
rescue SystemExit, SignalException
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.
# 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.
raise
raise exc
end
if exc
if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
Expand Down
4 changes: 2 additions & 2 deletions hbase-shell/src/main/ruby/jar-bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def debug?
# script calls 'exit' or 'exit 0' or 'exit errcode'.
if script2run
::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
exit @shell.exit_code unless @shell.exit_code.nil?
end
Expand All @@ -222,5 +222,5 @@ def debug?
# Output a banner message that tells users where to go for help
@shell.print_banner
end
IRB::HIRB.new(workspace).run
IRB::HIRB.new(workspace, interactive).run
exit @shell.exit_code unless interactive || @shell.exit_code.nil?