|
|
@ -21,11 +21,11 @@ class UnknownElementError(Exception): |
|
|
|
class FormatitkoRecursiveError(Exception): |
|
|
|
"A generic exception which wraps other exceptions and adds element-based traceback" |
|
|
|
elements: list[Union[Element, ListContainer, list[Union[Element, ListContainer]]]] |
|
|
|
file: str |
|
|
|
context: Context |
|
|
|
|
|
|
|
def __init__(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]], file: str, *args): |
|
|
|
def __init__(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]], context: Context, *args): |
|
|
|
self.elements = [e] |
|
|
|
self.file = file |
|
|
|
self.context = context |
|
|
|
super().__init__(args) |
|
|
|
|
|
|
|
def add_element(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]): |
|
|
@ -34,15 +34,21 @@ class FormatitkoRecursiveError(Exception): |
|
|
|
def pretty_print(self): |
|
|
|
def eprint(*args, **kwargs): |
|
|
|
print(*args, file=sys.stderr, **kwargs) |
|
|
|
eprint(f"Error occured in file {self.file} in ", end="") |
|
|
|
|
|
|
|
def print_filename_recursive(context: Context): |
|
|
|
return context.filename +\ |
|
|
|
((" (included from " + print_filename_recursive(context.parent) + ")") if context.parent else "") |
|
|
|
eprint(f"Error occured in file {print_filename_recursive(self.context)} in ", end="") |
|
|
|
line = None |
|
|
|
for i in range(len(self.elements)-1, 0, -1): |
|
|
|
if hasattr(self.elements[i], "content") and isinstance(self.elements[i].content[0], Inline): |
|
|
|
eprint() |
|
|
|
eprint('on line: "' + stringify(self.elements[i]) + '"', end="") |
|
|
|
break |
|
|
|
eprint(type(self.elements[i]).__name__ + "[" + str(self.elements[i-1].index) + "]", end=": ") |
|
|
|
if hasattr(self.elements[i], "content") and len(self.elements[i].content) > 0 and isinstance(self.elements[i].content[0], Inline) and line is None: |
|
|
|
line = self.elements[i] |
|
|
|
eprint(type(self.elements[i]).__name__ + "[" + (str(self.elements[i-1].index) if isinstance(self.elements[i-1].index, int) else "") + "]", end=": ") |
|
|
|
if line: |
|
|
|
eprint() |
|
|
|
eprint('on line: "' + stringify(line).strip() + '"', end="") |
|
|
|
eprint() |
|
|
|
eprint("in element: " + str(self.elements[0])) |
|
|
|
eprint("in element: " + str(self.elements[0]).replace("\n", "\\n")) |
|
|
|
sys.tracebacklimit = 0 |
|
|
|
raise self.__cause__ from None |
|
|
|
|
|
|
@ -161,7 +167,7 @@ class OutputGenerator: |
|
|
|
err.add_element(e) |
|
|
|
raise err |
|
|
|
except Exception as err: |
|
|
|
raise FormatitkoRecursiveError(e, self.context.filename) from err |
|
|
|
raise FormatitkoRecursiveError(e, self.context) from err |
|
|
|
|
|
|
|
def escape_special_chars(self, text: str) -> str: |
|
|
|
return text |
|
|
|