Skip to content

Commit c02ded0

Browse files
committed
Fix regex pattern to match exception names with alphanumeric characters and underscores in sentry_tools.py
The regular expression pattern used to find exceptions in strings has been updated to include alphanumeric characters and underscores. This ensures that exceptions with names like "pony_orm.core.TransactionIntegrityError" are correctly matched. Also, added test cases for strings that should not be matched in test_sentry_tools.py.
1 parent 491749c commit c02ded0

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/tribler/core/sentry_reporter/sentry_tools.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
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+(.+)')
14+
_re_search_exception = re.compile(r'^([A-Za-z0-9_.]+):\s+(.+)')
1515
_re_search_exception_exclusions = re.compile(r'(?:warning)', re.RegexFlag.IGNORECASE)
1616

1717
# Remove the substring like "Sentry is attempting to send 1 pending error messages"

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

+19-8
Original file line numberDiff line numberDiff line change
@@ -151,16 +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-
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
162171
('ERROR <exception_handler:100>', None),
163172
('PyInstaller\loader\pyimod03_importers.py:495', None),
173+
('foo:bar: baz', None),
174+
('foo<bar>: baz', None),
164175
]
165176

166177

0 commit comments

Comments
 (0)