import re


def parse_fatal_stacktrace(text):
    """Get useful information from a fatal faulthandler stacktrace.

    Args:
        text: The text to parse.

    Return:
        A tuple with the first element being the error type, and the second
        element being the first stacktrace frame.
    """
    lines = [
        r'(?P<type>Fatal Python error|Windows fatal exception): (?P<msg>.*)',
        r' *',
        r'(Current )?[Tt]hread [^ ]* \(most recent call first\): *',
        r'  File ".*", line \d+ in (?P<func>.*)',
    ]
    m = re.search('\n'.join(lines), text)
    if m is None:
        # We got some invalid text.
        return ('', '')
    else:
        msg = m.group('msg')
        typ = m.group('type')
        func = m.group('func')
        if typ == 'Windows fatal exception':
            msg = 'Windows ' + msg
        return msg, func