summaryrefslogtreecommitdiffstats
path: root/polymatrix/utils/tooperatorexception.py
blob: 5f7db0fe51a09e8f839f9180052e2c5a2e39e605 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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)