logging_handler: Resolve exception logging

This commit is contained in:
Mykola Grymalyuk
2023-05-22 10:58:49 -06:00
parent 1f23ceef7f
commit 422eee04b7
3 changed files with 25 additions and 11 deletions
+2
View File
@@ -44,6 +44,8 @@
- Utilize `py-applescript` for authorization prompts - Utilize `py-applescript` for authorization prompts
- Avoids displaying prompts with `osascript` in the title - Avoids displaying prompts with `osascript` in the title
- Due to limitations, only used for installer creation and OpenCore installation - 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: - Increment Binaries:
- PatcherSupportPkg 1.0.2 - release - PatcherSupportPkg 1.0.2 - release
- OpenCorePkg 0.9.2 - release - OpenCorePkg 0.9.2 - release
+20 -8
View File
@@ -1,10 +1,15 @@
import logging
import sys
import threading
import os import os
import sys
import logging
import threading
import traceback
import subprocess import subprocess
import applescript
from pathlib import Path from pathlib import Path
from resources import constants
class InitializeLoggingSupport: 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_filename: str = "OpenCore-Patcher.log"
self.log_filepath: Path = None self.log_filepath: Path = None
self.constants: constants.Constants = global_constants
self.original_excepthook: sys = sys.excepthook self.original_excepthook: sys = sys.excepthook
self.original_thread_excepthook: threading = threading.excepthook self.original_thread_excepthook: threading = threading.excepthook
@@ -43,10 +50,6 @@ class InitializeLoggingSupport:
self._fix_file_permission() self._fix_file_permission()
def __del__(self) -> None:
self._restore_original_excepthook()
def _initialize_logging_path(self) -> None: def _initialize_logging_path(self) -> None:
""" """
Initialize logging framework storage path Initialize logging framework storage path
@@ -156,6 +159,15 @@ class InitializeLoggingSupport:
""" """
logging.error("Uncaught exception in main thread", exc_info=(type, value, tb)) 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: def custom_thread_excepthook(args) -> None:
""" """
Reroute traceback in spawned thread to logging module Reroute traceback in spawned thread to logging module
+3 -3
View File
@@ -27,11 +27,9 @@ class OpenCoreLegacyPatcher:
""" """
def __init__(self) -> None: def __init__(self) -> None:
logging_handler.InitializeLoggingSupport()
self.constants: constants.Constants = constants.Constants() 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}...") 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 Generate base data required for the patcher to run
""" """
self.constants.wxpython_variant: bool = True
# Generate OS data # Generate OS data
os_data = os_probe.OSProbe() os_data = os_probe.OSProbe()
self.constants.detected_os = os_data.detect_kernel_major() self.constants.detected_os = os_data.detect_kernel_major()