Spaces:
Runtime error
Runtime error
File size: 533 Bytes
1c9e323 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | """
Exception related utilities
"""
import json
import traceback
def get_error_msg(error: Exception) -> str:
"""
Get error message (with stack trace) from an exception into a single json-serializable string.
This is useful for logging to a single line in the logs, which allows easy identification the associated exception,
rather than wondering which part of the logs belong to the same exception thrown.
"""
return json.dumps("".join(traceback.format_exception(type(error), error, error.__traceback__)))
|