authentik.lib.utils.errors
error utils
1"""error utils""" 2 3from traceback import extract_tb 4from typing import Any 5 6from structlog.tracebacks import ExceptionDictTransformer 7 8from authentik.lib.config import CONFIG 9from authentik.lib.utils.reflection import class_to_path 10 11TRACEBACK_HEADER = "Traceback (most recent call last):" 12_exception_transformer = ExceptionDictTransformer(show_locals=CONFIG.get_bool("debug")) 13 14 15def exception_to_string(exc: Exception) -> str: 16 """Convert exception to string stackrace""" 17 # Either use passed original exception or whatever we have 18 return "\n".join( 19 [ 20 TRACEBACK_HEADER, 21 *[x.rstrip() for x in extract_tb(exc.__traceback__).format()], 22 f"{class_to_path(exc.__class__)}: {str(exc)}", 23 ] 24 ) 25 26 27def exception_to_dict(exc: Exception) -> list[dict[str, Any]]: 28 """Format exception as a dictionary""" 29 return _exception_transformer((type(exc), exc, exc.__traceback__))
TRACEBACK_HEADER =
'Traceback (most recent call last):'
def
exception_to_string(exc: Exception) -> str:
16def exception_to_string(exc: Exception) -> str: 17 """Convert exception to string stackrace""" 18 # Either use passed original exception or whatever we have 19 return "\n".join( 20 [ 21 TRACEBACK_HEADER, 22 *[x.rstrip() for x in extract_tb(exc.__traceback__).format()], 23 f"{class_to_path(exc.__class__)}: {str(exc)}", 24 ] 25 )
Convert exception to string stackrace
def
exception_to_dict(exc: Exception) -> list[dict[str, typing.Any]]:
28def exception_to_dict(exc: Exception) -> list[dict[str, Any]]: 29 """Format exception as a dictionary""" 30 return _exception_transformer((type(exc), exc, exc.__traceback__))
Format exception as a dictionary