-
-
Save isc-shuliu/0814fc29b3b8794d4a9618513e553d8c to your computer and use it in GitHub Desktop.
Code for printing embedded Python traceback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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