Created
November 4, 2023 22:32
-
-
Save nonchris/1888ac5c6dc86b9f56f6ffd4942a021a to your computer and use it in GitHub Desktop.
might be helpful for someone
This file contains 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
# might be useful for someone - but traceback.format_exc() is honestly better | |
# but this version gives at least some understanding of whats happening | |
def exec_location_info(): | |
exc_type, exc_value, exc_traceback = sys.exc_info() | |
traceback_details = tb.extract_tb(exc_traceback, limit=None) | |
last_call = traceback_details[-1] | |
rel_path = os.path.relpath(last_call.filename) | |
return (f"{exc_type.__name__}: '{exc_value}', " | |
f"file: {rel_path}, " | |
f"line: {last_call.lineno} '{last_call.line}', " | |
f"function: {last_call.name}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment