Junegunn Choi created HBASE-30370:
-------------------------------------
Summary: Shell exits on errors other than NameError and SyntaxError
Key: HBASE-30370
URL: https://issues.apache.org/jira/browse/HBASE-30370
Project: HBase
Issue Type: Bug
Components: shell
Reporter: Junegunn Choi
h2. Problem
A mistyped command returns to the prompt, but any other error kills the
session, losing any local variables built up in it.
{noformat}
hbase:001:0> foot 'record'
undefined method `foot' ... (NoMethodError)
hbase:002:0> 1 + '2'
TypeError: String can't be coerced into Integer
... full JRuby backtrace, shell exits ...
{noformat}
HBase 1 printed the error and continued. The custom rescue block did not exist.
HBASE-26741 changed that for all exceptions in 2.4.10, 2.5.0 and 3.0.0-alpha-3.
HBASE-26880 and HBASE-27726 then restored the old behavior for one exception
class each.
{{hirb.rb}} rescues by class:
- {{SyntaxError}} (HBASE-27726) and {{NameError}} (HBASE-26880) fall through
to {{handle_exception}} and continue.
- Everything else hits the generic {{rescue Exception}} added by HBASE-26741
and is re-raised.
- {{NoMethodError}} survives only because it extends {{{}NameError{}}}.
The generic re-raise exists so that {{hbase shell script.rb}} sets a non-zero
exit code. That applies to the script path only. An interactive session is not
wrapped in {{{}Shell.exception_handler{}}}, and {{jar-bootstrap.rb}} skips the
exit code when interactive. So interactively the exception is not caught
anywhere, escapes to JRuby's default handler, and takes the session with it.
h2. Fix
Re-raise only when something consumes the exit code, which is a script run or
{{{}-n{}}}. Otherwise the error goes to {{handle_exception}} and the prompt
continues, as it did before HBASE-26741. The {{SyntaxError}} and {{NameError}}
clauses become redundant and are removed.
Gating on {{@interactive}} alone is not enough. {{interactive}} is only cleared
by {{{}-n{}}}, so {{hbase shell script.rb}} would stop exiting non-zero and
would fall through to a prompt. A script run is instead identified by the
{{IRB::FileInputMethod}} that {{HBaseLoader.file_for_load}} returns.
{{SystemExit}} and {{SignalException}} still re-raise unconditionally, so
{{exit}} and signals are unaffected.
h2. Behavior
With {{{}script.rb{}}}:
{code:java|title=script.rb}
1 + '2'
puts 'hello'
{code}
||case||before||after||
|interactive, {{NameError}} or {{SyntaxError}}|prompt continues|prompt
continues|
|interactive, any other error|session exits|prompt continues|
|{{hbase shell script.rb}}|exit 1|exit 1|
|{{hbase shell -n script.rb}}|exit 1|exit 1|
|either form, error-free script|exit 0|exit 0|
--
This message was sent by Atlassian Jira
(v8.20.10#820010)