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

Extract a real core error from CoreError for the Sentry Reporter #7072

Merged
merged 1 commit into from Oct 3, 2022

Conversation

drew2a
Copy link
Collaborator

@drew2a drew2a commented Sep 29, 2022

This PR closes #7066 by adding the last_core_output argument for the function SentryReporter.send_event().
If this argument is presented, then a Sentry Event will be formatted in the following way:

    def send_event(self, event: Dict = None, post_data: Dict = None, sys_info: Dict = None,
                   additional_tags: List[str] = None, last_core_output: Optional[str] = None):
   
        ...

        # try to retrieve an error from the last_core_output
        if last_core_output:
            reporter['last_core_output'] = last_core_output.split('\n')
            if last_core_exception := parse_last_core_output(last_core_output):
                exceptions = event.get(EXCEPTION, {})
                gui_exception = get_last_item(exceptions.get(VALUES, []), {})
                core_exception = {'type': last_core_exception.type, 'value': last_core_exception.message}
                delete_item(gui_exception, 'stacktrace')

                exceptions[VALUES] = [gui_exception, core_exception]

        ...

Where parse_last_core_output is

_re_search_exception = re.compile(r'^(\S+)\s*:\s*(.+)')
_re_remove_sentry = re.compile(r'Sentry is attempting.*')

@dataclass
class LastCoreException:
    type: str
    message: str


def parse_last_core_output(text: str) -> Optional[LastCoreException]:
    def _clean_up(s: str):
        return _re_remove_sentry.sub('', s).strip()

    for line in reversed(text.split('\n')):
        if m := _re_search_exception.match(line):
            return LastCoreException(type=_clean_up(m.group(1)),
                                     message=_clean_up(m.group(2)))
    return None

The new Sentry Event: https://sentry.tribler.org/organizations/tribler/issues/1747

@drew2a drew2a marked this pull request as ready for review September 29, 2022 15:19
@drew2a drew2a requested a review from a team as a code owner September 29, 2022 15:20
@drew2a drew2a requested review from xoriole and kozlovsky and removed request for a team September 29, 2022 15:20
@drew2a drew2a merged commit d5b4832 into Tribler:main Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract a real core error from CoreCrashedError for the Sentry Reporter
2 participants