# SPDX-License-Identifier: GPLv3-or-later
# Copyright © 2025 pygaindalf Rui Pinheiro
import logging
import sys
from types import TracebackType
# Logs uncaught exceptions using "logging" object, this way they also show up in the log
[docs]
def handle_exception(
exc_type: type[BaseException],
exc_value: BaseException,
exc_traceback: TracebackType | None,
) -> None:
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logging.critical("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback)) # noqa: LOG015 as we don't know if logging is properly configured
sys.excepthook = handle_exception