diff --git a/hbase-shell/src/main/ruby/irb/hirb.rb b/hbase-shell/src/main/ruby/irb/hirb.rb index 9a81f5abc77d..7fc409124895 100644 --- a/hbase-shell/src/main/ruby/irb/hirb.rb +++ b/hbase-shell/src/main/ruby/irb/hirb.rb @@ -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 @@ -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 @@ -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/ && diff --git a/hbase-shell/src/main/ruby/jar-bootstrap.rb b/hbase-shell/src/main/ruby/jar-bootstrap.rb index ee2fe9fd21e9..917817fc59f9 100644 --- a/hbase-shell/src/main/ruby/jar-bootstrap.rb +++ b/hbase-shell/src/main/ruby/jar-bootstrap.rb @@ -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 @@ -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?