|
9 | 9 |
|
10 | 10 | ENHANCED_REPORT = os.environ.get('ENHANCED_REPORT', True) |
11 | 11 |
|
| 12 | +def is_recursion_error(python_version: str, result: Result) -> bool: |
| 13 | + """ |
| 14 | + Check if the result is a recursion error |
| 15 | + """ |
| 16 | + if result.outcome == 'RecursionError': |
| 17 | + return True |
| 18 | + |
| 19 | + if python_version in ['2.7', '3.3', '3.4']: |
| 20 | + # In these versions, the recursion error is raised as an Exception |
| 21 | + return result.outcome.startswith('Exception: maximum recursion depth exceeded') |
| 22 | + |
| 23 | + return False |
| 24 | + |
| 25 | +def is_syntax_error(python_version: str, result: Result) -> bool: |
| 26 | + """ |
| 27 | + Check if the result is a syntax error |
| 28 | + """ |
| 29 | + if result.outcome == 'SyntaxError': |
| 30 | + return True |
| 31 | + |
| 32 | + if python_version == '2.7' and result.outcome == 'Exception: compile() expected string without null bytes': |
| 33 | + return True |
| 34 | + |
| 35 | + if python_version != '2.7' and result.outcome == 'Exception: source code string cannot contain null bytes': |
| 36 | + return True |
| 37 | + |
| 38 | + return False |
12 | 39 |
|
13 | 40 | @dataclass |
14 | 41 | class ResultSet: |
@@ -45,11 +72,11 @@ def add(self, result: Result): |
45 | 72 | if result.original_size < result.minified_size: |
46 | 73 | self.larger_than_original_count += 1 |
47 | 74 |
|
48 | | - if result.outcome == 'RecursionError': |
| 75 | + if is_recursion_error(self.python_version, result): |
49 | 76 | self.recursion_error_count += 1 |
50 | 77 | elif result.outcome == 'UnstableMinification': |
51 | 78 | self.unstable_minification_count += 1 |
52 | | - elif result.outcome.startswith('Exception') and result.outcome != 'Exception: source code string cannot contain null bytes': |
| 79 | + elif result.outcome.startswith('Exception') is not is_syntax_error(self.python_version, result): |
53 | 80 | self.exception_count += 1 |
54 | 81 |
|
55 | 82 | @property |
|
0 commit comments