Skip to content

Instantly share code, notes, and snippets.

@isc-shuliu
Created December 15, 2024 01:50
Show Gist options
  • Select an option

  • Save isc-shuliu/0814fc29b3b8794d4a9618513e553d8c to your computer and use it in GitHub Desktop.

Select an option

Save isc-shuliu/0814fc29b3b8794d4a9618513e553d8c to your computer and use it in GitHub Desktop.
Code for printing embedded Python traceback
import iris
import sys
from traceback import walk_tb
def helper(tb):
for frame, lineno in walk_tb(tb):
filename = frame.f_globals.get("__name__", None)
methodname = frame.f_code.co_name
lineno -= frame.f_code.co_firstlineno
line = iris.gref("oddDEF")[filename, "m", methodname, 30, lineno] or ""
yield filename, methodname, lineno, line.strip()
def print_iris_exc(file=None) -> None:
etype, e, tb = sys.exc_info()
print("Embedded Python Traceback (most recent call last):", file=file)
for filename, methodname, lineno, line in helper(tb):
print(f' ObjectScript Class "{filename}", Method "{methodname}", Line {lineno}', file=file)
if line:
print(f' {line}', file=file)
print(f"{etype.__name__}: {e}", file=file)
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment