def bugzilla_thread_frames()

in bugbot/crash/socorro_util.py [0:0]


def bugzilla_thread_frames(thread):
    """Build frame information for bug creation link

    Extract frame info for the top frames of a crashing thread to be included in the
    Bugzilla summary when reporting the crash.

    :arg thread: dict of thread information including "frames" list

    :returns: list of frame information dicts

    """

    def frame_generator(thread):
        """Yield frames in a thread factoring in inlines"""
        for frame in thread["frames"]:
            for inline in frame.get("inlines") or []:
                yield {
                    "frame": frame.get("frame", "?"),
                    "module": frame.get("module", ""),
                    "signature": inline["function"],
                    "file": inline["file"],
                    "line": inline["line"],
                }

            yield frame

    # We only want to include 10 frames in the link
    MAX_FRAMES = 10

    frames = []
    for frame in islice(frame_generator(thread), MAX_FRAMES):
        # Source is an empty string if data isn't available
        source = frame.get("file") or ""
        if frame.get("line"):
            source += ":{}".format(frame["line"])

        signature = frame.get("signature") or ""

        # Remove function arguments
        if not signature.startswith("(unloaded"):
            signature = re.sub(r"\(.*\)", "", signature)

        frames.append(
            {
                "frame": frame.get("frame", "?"),
                "module": frame.get("module") or "?",
                "signature": signature,
                "source": source,
            }
        )

    return frames