summaryrefslogtreecommitdiffstats
path: root/polymatrix/utils/tooperatorexception.py
blob: 1c84be7c535a356e540e4f97519c9e279f5cda62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from polymatrix.utils.getstacklines import FrameSummary


def to_operator_exception(
    message: str,
    stack: tuple[FrameSummary],
) -> str:
    exception_lines = [
        message,
        f"  Assertion traceback (most recent call last):",
        *(
            f'    File "{stack_line.filename}", line {stack_line.lineno}\n      {stack_line.line}'
            for stack_line in stack
        ),
    ]

    return "\n".join(exception_lines)