Skip to content

Instantly share code, notes, and snippets.

@Shuhala
Created November 21, 2019 18:50
Show Gist options
  • Save Shuhala/58dd08a1286503a3d8d3449f1420dfed to your computer and use it in GitHub Desktop.
Save Shuhala/58dd08a1286503a3d8d3449f1420dfed 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