mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
9dc21f8d0b
Summary: D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`. That has nasty problems if both `import mercurial` and `import edenscm.mercurial` are used, because Python would think `mercurial.foo` and `edenscm.mercurial.foo` are different modules so code like `try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)` would fail to handle the `edenscm.mercurial` version. There are also some module-level states (ex. `extensions._extensions`) that would cause trouble if they have multiple versions in a single process. Change imports to use the `edenscm` so ideally the `mercurial` is no longer imported at all. Add checks in extensions.py to catch unexpected extensions importing modules from the old (wrong) locations when running tests. Reviewed By: phillco Differential Revision: D13868981 fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
75 lines
2.6 KiB
Perl
75 lines
2.6 KiB
Perl
$ cat > $TESTTMP/crash.py << EOF
|
|
> from edenscm.mercurial import registrar
|
|
> cmdtable = {}
|
|
> command = registrar.command(cmdtable)
|
|
> @command('crash', [])
|
|
> def crash(ui, repo):
|
|
> raise 'crash'
|
|
> EOF
|
|
$ cat >> $HGRCPATH << EOF
|
|
> [extensions]
|
|
> errorredirect=
|
|
> 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
|
|
$ hg crash --config errorredirect.script='echo overridden-message'
|
|
overridden-message
|
|
[255]
|
|
|
|
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
|
|
* @0000000000000000000000000000000000000000 (*) [command]> blackbox -l 2 (glob)
|
|
$ 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)
|