2015-12-04 02:03:07 +03:00
|
|
|
$ cat > $TESTTMP/crash.py << EOF
|
2017-05-22 23:38:37 +03:00
|
|
|
> from mercurial import registrar
|
2015-12-04 02:03:07 +03:00
|
|
|
> cmdtable = {}
|
2017-05-22 23:38:37 +03:00
|
|
|
> command = registrar.command(cmdtable)
|
2015-12-04 02:03:07 +03:00
|
|
|
> @command('crash', [])
|
|
|
|
> def crash(ui, repo):
|
|
|
|
> raise 'crash'
|
|
|
|
> EOF
|
|
|
|
$ cat >> $HGRCPATH << EOF
|
|
|
|
> [extensions]
|
2017-06-17 04:31:25 +03:00
|
|
|
> errorredirect=$TESTDIR/../hgext3rd/errorredirect.py
|
2015-12-04 02:03:07 +03:00
|
|
|
> crash=$TESTTMP/crash.py
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
Test errorredirect will respect original behavior by default
|
|
|
|
$ hg init
|
|
|
|
$ hg crash 2>&1 | grep -o 'Unknown exception encountered'
|
|
|
|
Unknown exception encountered
|
|
|
|
|
|
|
|
Test the errorredirect script will override stack trace output
|
2016-04-04 22:48:01 +03:00
|
|
|
$ hg crash --config errorredirect.script='echo overridden-message'
|
|
|
|
overridden-message
|
errorredirect: wrap handlecommandexception instead of sys.exit
Summary:
Since `handlecommandexception` is in core, wrap it to suppress original
crash text, instead of doing an ugly `sys.exit()`. It's much simpler and
cleaner than before. It also fixes an issue with current chg since chgserver
will print an traceback when it encounters SystemExit.
Although `logtoprocess` are doing very similar things with `errorredirect`,
it currently cannot replace `errorredirect` because we need synchronized
behavior to return the user to their shell prompt correctly. If we can get
the synchronized behavior and a way to disable builtin warning (may be tricky)
in `logtoprocess` upstream, the `errorredirect` extension could be just a thin
wrapper around `logtoprocess` using `setconfig`.
Besides, we no longer need `suppresscommandfailure` since the feature will
be either in `errorredirect` or `logtoprocess`.
Test Plan:
Run `hg crash` with `errorredirect.script` set to confirm it is compatible
with the old behavior.
Also run unittest `test-errorredirect.t`
Reviewers: #sourcecontrol, ttung, mjpieters
Reviewed By: mjpieters
Subscribers: rmcelroy, durham, lcharignon, mjpieters
Differential Revision: https://phabricator.fb.com/D3191840
Signature: t1:3191840:1461088280:77febd539c2f38a55778af3977738c045f63a0d8
2016-04-19 20:59:22 +03:00
|
|
|
[255]
|
2017-04-04 20:27:30 +03:00
|
|
|
|
|
|
|
If the script returns non-zero, print the trace
|
|
|
|
$ hg crash --config errorredirect.script='echo It works && exit 1' 2>&1 | grep '^[IT]'
|
|
|
|
It works
|
|
|
|
Traceback (most recent call last):
|
|
|
|
TypeError: exceptions must be old-style classes or derived from BaseException, not str
|
|
|
|
|
|
|
|
$ printf '#!%sbin/sh\necho It works && false' '/' > a.sh
|
|
|
|
$ chmod +x $TESTTMP/a.sh
|
|
|
|
$ PATH=$TESTTMP:$PATH hg crash --config errorredirect.script=a.sh 2>&1 | grep '^[IT]'
|
|
|
|
It works
|
|
|
|
Traceback (most recent call last):
|
|
|
|
TypeError: exceptions must be old-style classes or derived from BaseException, not str
|
|
|
|
|
|
|
|
If the script is terminated by SIGTERM (Ctrl+C), do not print the trace
|
|
|
|
$ hg crash --config errorredirect.script='echo It works && kill -TERM $$' 2>&1
|
|
|
|
It works
|
|
|
|
[255]
|
|
|
|
|
|
|
|
$ printf '#!%sbin/sh\necho It works && kill -TERM $$' '/' > a.sh
|
|
|
|
$ chmod +x $TESTTMP/a.sh
|
|
|
|
$ PATH=$TESTTMP:$PATH hg crash --config errorredirect.script=a.sh 2>&1
|
|
|
|
It works
|
|
|
|
[255]
|
|
|
|
|
|
|
|
If the script cannot be executed (not found in PATH), print the trace
|
|
|
|
$ hash SCRIPT-DOES-NOT-EXIST 2>/dev/null && exit 80
|
|
|
|
[1]
|
|
|
|
$ hg crash --config errorredirect.script='SCRIPT-DOES-NOT-EXIST' 2>&1 | grep '^[IT]'
|
|
|
|
Traceback (most recent call last):
|
|
|
|
TypeError: exceptions must be old-style classes or derived from BaseException, not str
|
|
|
|
|
|
|
|
Traces are logged in blackbox
|
|
|
|
$ cat >> $HGRCPATH << EOF
|
|
|
|
> [extensions]
|
|
|
|
> blackbox=
|
|
|
|
> [blackbox]
|
|
|
|
> track = command, commandexception
|
|
|
|
> logsource = 1
|
|
|
|
> EOF
|
|
|
|
|
|
|
|
$ hg blackbox -l 2
|
2017-04-05 01:00:52 +03:00
|
|
|
* @0000000000000000000000000000000000000000 (*) [command]> blackbox -l 2 (glob)
|
2017-04-04 20:27:30 +03:00
|
|
|
$ hg crash --config errorredirect.script='echo Works'
|
|
|
|
Works
|
|
|
|
[255]
|
|
|
|
$ hg blackbox -l 12 | grep '\[command'
|
|
|
|
* @0000000000000000000000000000000000000000 (*) [command]> blackbox -l 2 (glob)
|
|
|
|
* @0000000000000000000000000000000000000000 (*) [command]> crash (glob)
|
|
|
|
* @0000000000000000000000000000000000000000 (*) [commandexception]> * (glob)
|
|
|
|
* @0000000000000000000000000000000000000000 (*) [command]> blackbox -l 12 (glob)
|