An error tracker receives raw Python tracebacks as text. Turn one into structured data and remove frames from library code so only the application's own frames remain.
Write parse_traceback(text, ignore=("site-packages", "<frozen")) that returns a dictionary:
{"exception": str, "message": str, "frames": [{"file": str, "line": int, "function": str, "code": str}, ...], "dropped": int}
The input looks like the output of an uncaught exception:
Traceback (most recent call last):
File "/app/main.py", line 12, in <module>
run()
File "/usr/lib/python3.11/site-packages/lib/core.py", line 88, in call
return fn()
ValueError: bad value: 3
File "<path>", line <n>, in <function> (with leading spaces). The next line, if it is more indented and is not another File line, is the frame's source code (stripped). Otherwise code is "". Lines made only of whitespace, ^ and ~ (error markers under the code) are ignored.": " into exception and message; with no ": " the whole line is the exception and the message is "".Traceback blocks. Parse only the last one.ignore; dropped counts them. Kept frames stay in their original order (outermost first).