Last active
June 19, 2022 18:33
-
-
Save aredden/b8bcc6c8e3dd2b2de90e27e7a22fc9e0 to your computer and use it in GitHub Desktop.
proper python error formatting without necessary non-zero exit code.
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
| from traceback import format_exception | |
| def format_error(e: Exception, limit: int = 3): | |
| """Format exception as a string. | |
| Args: | |
| e (Exception): Raised exception object. | |
| limit (int): limit of error call stack lines to be included in the formatted string. | |
| """ | |
| e_fmt = format_exception(type(e), e, tb=e.__traceback__, limit=limit) | |
| return "\n".join(e_fmt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment