Skip to content

Commit 1d8a5bf

Browse files
authored
HBASE-26880 Misspelling commands in hbase shell will crash the shell (#4325)
Signed-off-by: Andrew Purtell <[email protected]>
1 parent 3ae0d90 commit 1d8a5bf

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

hbase-shell/src/main/ruby/irb/hirb.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module IRB
2323

2424
# Subclass of IRB so can intercept methods
2525
class HIRB < Irb
26-
def initialize(workspace = nil, input_method = nil)
26+
def initialize(workspace = nil, interactive = true, input_method = nil)
2727
# This is ugly. Our 'help' method above provokes the following message
2828
# on irb construction: 'irb: warn: can't alias help from irb_help.'
2929
# Below, we reset the output so its pointed at /dev/null during irb
@@ -46,6 +46,7 @@ def initialize(workspace = nil, input_method = nil)
4646
if $stdin.tty?
4747
`stty icrnl <&2`
4848
end
49+
@interactive = interactive
4950
super(workspace, input_method)
5051
ensure
5152
f.close
@@ -117,11 +118,14 @@ def eval_input
117118
rescue Interrupt => exc
118119
rescue SystemExit, SignalException
119120
raise
120-
rescue Exception
121+
rescue NameError => exc
122+
raise exc unless @interactive
123+
# HBASE-26880: Ignore NameError to prevent exiting Shell on mistyped commands.
124+
rescue Exception => exc
121125
# HBASE-26741: Raise exception so Shell::exception_handler can catch it.
122126
# This modifies this copied method from JRuby so that the HBase shell can
123127
# manage the exception and set a proper exit code on the process.
124-
raise
128+
raise exc
125129
end
126130
if exc
127131
if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&

hbase-shell/src/main/ruby/jar-bootstrap.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def debug?
213213
# script calls 'exit' or 'exit 0' or 'exit errcode'.
214214
if script2run
215215
::Shell::Shell.exception_handler(!full_backtrace) do
216-
IRB::HIRB.new(workspace, IRB::HBaseLoader.file_for_load(script2run)).run
216+
IRB::HIRB.new(workspace, interactive, IRB::HBaseLoader.file_for_load(script2run)).run
217217
end
218218
exit @shell.exit_code unless @shell.exit_code.nil?
219219
end
@@ -222,5 +222,5 @@ def debug?
222222
# Output a banner message that tells users where to go for help
223223
@shell.print_banner
224224
end
225-
IRB::HIRB.new(workspace).run
225+
IRB::HIRB.new(workspace, interactive).run
226226
exit @shell.exit_code unless interactive || @shell.exit_code.nil?

0 commit comments

Comments
 (0)