Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an exclusion for the exception type found in the latest core output. #7722

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/tribler/core/sentry_reporter/sentry_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
CONTEXT_DELIMITER = '--CONTEXT--'

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

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

for line in reversed(text.split('\n')):
if m := _re_search_exception.match(line):
return LastCoreException(type=_clean_up(m.group(1)),
exception_type = m.group(1)
if _re_search_exception_exclusions.search(exception_type):
continue # find an exclusion

return LastCoreException(type=_clean_up(exception_type),
message=_clean_up(m.group(2)))
return None

Expand Down
49 changes: 39 additions & 10 deletions src/tribler/core/sentry_reporter/tests/test_sentry_tools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from tribler.core.sentry_reporter.sentry_tools import (
_re_search_exception, delete_item,
_re_search_exception, _re_search_exception_exclusions, delete_item,
distinct_by,
extract_dict,
format_version,
Expand Down Expand Up @@ -151,15 +151,27 @@ def test_extract_dict():
]

EXCEPTION_STRINGS = [
('OverflowError: bind(): port must be 0-65535',
('OverflowError', 'bind(): port must be 0-65535'),
),

("pony.orm.core.TransactionIntegrityError : MiscData['db_version'] cannot be stored. IntegrityError: UNIQUE",
('pony.orm.core.TransactionIntegrityError', "MiscData['db_version'] cannot be stored. IntegrityError: UNIQUE"),
),

('ERROR <exception_handler:100>', None)
(
'OverflowError: bind(): port must be 0-65535',
(
'OverflowError',
'bind(): port must be 0-65535'
),
),

(
"pony_orm.core.TransactionIntegrityError: MiscData['db_version'] cannot be stored. IntegrityError: UNIQUE",
(
'pony_orm.core.TransactionIntegrityError',
"MiscData['db_version'] cannot be stored. IntegrityError: UNIQUE"
),
),

# Strings thst should not be matched
('ERROR <exception_handler:100>', None),
('PyInstaller\loader\pyimod03_importers.py:495', None),
('foo:bar: baz', None),
('foo<bar>: baz', None),
]


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


EXCEPTION_EXCLUSIONS_STRINGS = [
'UserWarning',
]


@pytest.mark.parametrize('given', EXCEPTION_EXCLUSIONS_STRINGS)
def test_re_search_exception_exclusions(given):
# Test that `_re_search_exception_exclusions` matches with the expected values from the
# `EXCEPTION_EXCLUSIONS_STRINGS`
assert _re_search_exception_exclusions.search(given)


def test_parse_last_core_output():
# Test that `parse_last_core_output` correctly extract the last core exception from the real raw core output

Expand Down Expand Up @@ -211,3 +235,8 @@ def test_parse_last_core_output_no_match():

last_core_exception = parse_last_core_output('last core output without exceptions')
assert not last_core_exception


def test_parse_last_core_output_exclusion():
last_core_exception = parse_last_core_output('UserWarning: You are using cryptography on a 32-bit Python on a...')
assert not last_core_exception