Skip to content

Commit 17a5783

Browse files
authored
Merge pull request #7722 from drew2a/fix/7713_1
Add an exclusion for the exception type found in the latest core output.
2 parents 3e2eb93 + c02ded0 commit 17a5783

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

src/tribler/core/sentry_reporter/sentry_tools.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
CONTEXT_DELIMITER = '--CONTEXT--'
1212

1313
# Find an exception in the string like: "OverflowError: bind(): port must be 0-65535"
14-
_re_search_exception = re.compile(r'^(\S+)\s*:\s*(.+)')
14+
_re_search_exception = re.compile(r'^([A-Za-z0-9_.]+):\s+(.+)')
15+
_re_search_exception_exclusions = re.compile(r'(?:warning)', re.RegexFlag.IGNORECASE)
1516

1617
# Remove the substring like "Sentry is attempting to send 1 pending error messages"
1718
_re_remove_sentry = re.compile(r'Sentry is attempting.*')
@@ -89,7 +90,11 @@ def _clean_up(s: str):
8990

9091
for line in reversed(text.split('\n')):
9192
if m := _re_search_exception.match(line):
92-
return LastCoreException(type=_clean_up(m.group(1)),
93+
exception_type = m.group(1)
94+
if _re_search_exception_exclusions.search(exception_type):
95+
continue # find an exclusion
96+
97+
return LastCoreException(type=_clean_up(exception_type),
9398
message=_clean_up(m.group(2)))
9499
return None
95100

src/tribler/core/sentry_reporter/tests/test_sentry_tools.py

+39-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from tribler.core.sentry_reporter.sentry_tools import (
4-
_re_search_exception, delete_item,
4+
_re_search_exception, _re_search_exception_exclusions, delete_item,
55
distinct_by,
66
extract_dict,
77
format_version,
@@ -151,15 +151,27 @@ def test_extract_dict():
151151
]
152152

153153
EXCEPTION_STRINGS = [
154-
('OverflowError: bind(): port must be 0-65535',
155-
('OverflowError', 'bind(): port must be 0-65535'),
156-
),
157-
158-
("pony.orm.core.TransactionIntegrityError : MiscData['db_version'] cannot be stored. IntegrityError: UNIQUE",
159-
('pony.orm.core.TransactionIntegrityError', "MiscData['db_version'] cannot be stored. IntegrityError: UNIQUE"),
160-
),
161-
162-
('ERROR <exception_handler:100>', None)
154+
(
155+
'OverflowError: bind(): port must be 0-65535',
156+
(
157+
'OverflowError',
158+
'bind(): port must be 0-65535'
159+
),
160+
),
161+
162+
(
163+
"pony_orm.core.TransactionIntegrityError: MiscData['db_version'] cannot be stored. IntegrityError: UNIQUE",
164+
(
165+
'pony_orm.core.TransactionIntegrityError',
166+
"MiscData['db_version'] cannot be stored. IntegrityError: UNIQUE"
167+
),
168+
),
169+
170+
# Strings thst should not be matched
171+
('ERROR <exception_handler:100>', None),
172+
('PyInstaller\loader\pyimod03_importers.py:495', None),
173+
('foo:bar: baz', None),
174+
('foo<bar>: baz', None),
163175
]
164176

165177

@@ -180,6 +192,18 @@ def test_parse_last_core_output_re(given, expected):
180192
assert m == expected
181193

182194

195+
EXCEPTION_EXCLUSIONS_STRINGS = [
196+
'UserWarning',
197+
]
198+
199+
200+
@pytest.mark.parametrize('given', EXCEPTION_EXCLUSIONS_STRINGS)
201+
def test_re_search_exception_exclusions(given):
202+
# Test that `_re_search_exception_exclusions` matches with the expected values from the
203+
# `EXCEPTION_EXCLUSIONS_STRINGS`
204+
assert _re_search_exception_exclusions.search(given)
205+
206+
183207
def test_parse_last_core_output():
184208
# Test that `parse_last_core_output` correctly extract the last core exception from the real raw core output
185209

@@ -211,3 +235,8 @@ def test_parse_last_core_output_no_match():
211235

212236
last_core_exception = parse_last_core_output('last core output without exceptions')
213237
assert not last_core_exception
238+
239+
240+
def test_parse_last_core_output_exclusion():
241+
last_core_exception = parse_last_core_output('UserWarning: You are using cryptography on a 32-bit Python on a...')
242+
assert not last_core_exception

0 commit comments

Comments
 (0)