-
-
Save davidimoore/cae9c9a0fdd7120ca5f79e7f0019269a to your computer and use it in GitHub Desktop.
Serialize python exceptions into dictionaries
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
import traceback | |
from typing import Dict, Union, List | |
def traceback_exc(exc: Exception) -> Dict[str, Union[str, List[str]]]: | |
tb = traceback.TracebackException.from_exception( | |
exc, capture_locals=True | |
) | |
return { | |
"title": type(exc).__name__, | |
"message": str(exc), | |
"traceback": [line.split("\n") for line in tb.format()], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment