diff --git a/CHANGELOG.md b/CHANGELOG.md index e473e44ef..e350d6361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,8 @@ - Utilize `py-applescript` for authorization prompts - Avoids displaying prompts with `osascript` in the title - Due to limitations, only used for installer creation and OpenCore installation + - Resolve exception handler not logging to file + - Display raised exceptions from main thread to users - Increment Binaries: - PatcherSupportPkg 1.0.2 - release - OpenCorePkg 0.9.2 - release diff --git a/resources/logging_handler.py b/resources/logging_handler.py index b834e89f5..cddaa85e0 100644 --- a/resources/logging_handler.py +++ b/resources/logging_handler.py @@ -1,10 +1,15 @@ -import logging -import sys -import threading import os +import sys +import logging +import threading +import traceback import subprocess +import applescript + from pathlib import Path +from resources import constants + class InitializeLoggingSupport: """ @@ -26,10 +31,12 @@ class InitializeLoggingSupport: """ - def __init__(self) -> None: + def __init__(self, global_constants: constants.Constants) -> None: self.log_filename: str = "OpenCore-Patcher.log" self.log_filepath: Path = None + self.constants: constants.Constants = global_constants + self.original_excepthook: sys = sys.excepthook self.original_thread_excepthook: threading = threading.excepthook @@ -43,10 +50,6 @@ class InitializeLoggingSupport: self._fix_file_permission() - def __del__(self) -> None: - self._restore_original_excepthook() - - def _initialize_logging_path(self) -> None: """ Initialize logging framework storage path @@ -156,6 +159,15 @@ class InitializeLoggingSupport: """ logging.error("Uncaught exception in main thread", exc_info=(type, value, tb)) + error_msg = f"OpenCore Legacy Patcher encountered the following internal error:\n\n" + error_msg += f"{type.__name__}: {value}" + if tb: + error_msg += f"\n\n{traceback.extract_tb(tb)[-1]}" + error_msg += "\n\nPlease report this error on our Discord server." + + applescript.AppleScript(f'display dialog "{error_msg}" with title "OpenCore Legacy Patcher ({self.constants.patcher_version})" buttons {{"OK"}} default button "OK" with icon caution giving up after 30').run() + + def custom_thread_excepthook(args) -> None: """ Reroute traceback in spawned thread to logging module diff --git a/resources/main.py b/resources/main.py index 9797cfcdf..f2ab0dc38 100644 --- a/resources/main.py +++ b/resources/main.py @@ -27,11 +27,9 @@ class OpenCoreLegacyPatcher: """ def __init__(self) -> None: - logging_handler.InitializeLoggingSupport() - self.constants: constants.Constants = constants.Constants() - self.constants.wxpython_variant: bool = True + logging_handler.InitializeLoggingSupport(self.constants) logging.info(f"- Loading OpenCore Legacy Patcher v{self.constants.patcher_version}...") @@ -46,6 +44,8 @@ class OpenCoreLegacyPatcher: Generate base data required for the patcher to run """ + self.constants.wxpython_variant: bool = True + # Generate OS data os_data = os_probe.OSProbe() self.constants.detected_os = os_data.detect_kernel_major()