Mercurial > hg
annotate tests/filtertraceback.py @ 45825:8f07f5a9c3de
worker: raise exception instead of calling sys.exit() with child's code
When a worker process returns an error code, we would call
`sys.exit()` with that exit code on the main process. The `SystemExit`
exception would then get caught in `scmutil.callcatch()`, which would
return that error code. The comment there says "Commands shouldn't
sys.exit directly", which I agree with. This patch changes it so we
raise a specific exception when a worker fails so we can catch
instead. I think that means that `SystemExit` is now always an
internal error.
(I had earlier thought that this call to `sys.exit()` was from within
the child process until Matt Harbison made me look again, so thanks
for that!)
Differential Revision: https://phab.mercurial-scm.org/D9287
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sat, 07 Nov 2020 21:50:28 -0800 |
parents | d359f0d1a3d3 |
children | c102b704edb5 |
rev | line source |
---|---|
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Filters traceback lines from stdin. |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 from __future__ import absolute_import, print_function |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 |
44654
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
7 import io |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 import sys |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
44654
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
10 if sys.version_info[0] >= 3: |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
11 # Prevent \r from being inserted on Windows. |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
12 sys.stdout = io.TextIOWrapper( |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
13 sys.stdout.buffer, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
14 sys.stdout.encoding, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
15 sys.stdout.errors, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
16 newline="\n", |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
17 line_buffering=sys.stdout.line_buffering, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
18 ) |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
19 |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 state = 'none' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 for line in sys.stdin: |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 if state == 'none': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 if line.startswith('Traceback '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 state = 'tb' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 elif state == 'tb': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 if line.startswith(' File '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 state = 'file' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 continue |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 elif not line.startswith(' '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 state = 'none' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 elif state == 'file': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 # Ignore lines after " File " |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 state = 'tb' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 continue |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 print(line, end='') |