Skip to content

Instantly share code, notes, and snippets.

@Shuhala
Created November 21, 2019 18:50
Show Gist options
  • Save Shuhala/aa4d25c3e2dcc9d0a90243145580d011 to your computer and use it in GitHub Desktop.
Save Shuhala/aa4d25c3e2dcc9d0a90243145580d011 to your computer and use it in GitHub Desktop.
import traceback
from typing import Optional, Union
def format_exception(exception: Optional[Union[Exception, BaseException]]) -> str:
""" Format a prettier exception trace """
if exception:
return f"\n{type(exception).__name__} Exception: {exception}" f"\n{''.join(traceback.format_tb(exception.__traceback__))}"
return " Exception."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment