From 9e14a778aa9c00efaf7403a899a001c3164090ac Mon Sep 17 00:00:00 2001 From: Hoang Hong Quan Date: Tue, 8 Oct 2024 00:58:37 +0700 Subject: [PATCH] Add detailed error info for easier debugging --- OpCore-Simplify.py | 19 ++++++++++++------- Scripts/utils.py | 27 +++++---------------------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/OpCore-Simplify.py b/OpCore-Simplify.py index dce0a9d..273c169 100644 --- a/OpCore-Simplify.py +++ b/OpCore-Simplify.py @@ -11,6 +11,7 @@ import updater import os import sys import re +import traceback class OCPE: def __init__(self): @@ -201,12 +202,16 @@ class OCPE: self.results(hardware_report, smbios_model) if __name__ == '__main__': + update_flag = updater.Updater().run_update() + if update_flag: + os.execv(sys.executable, ['python3'] + sys.argv) + o = OCPE() - try: - update_flag = updater.Updater().run_update() - if update_flag: - os.execv(sys.executable, ['python3'] + sys.argv) - else: + while True: + try: o.main() - except Exception as e: - o.u.exit_program(o.u.message("\nAn error occurred: {}\n".format(e))) \ No newline at end of file + except Exception as e: + o.u.head("An Error Occurred") + print("") + print(traceback.format_exc()) + o.u.request_input() \ No newline at end of file diff --git a/Scripts/utils.py b/Scripts/utils.py index cd2ffa1..5296067 100644 --- a/Scripts/utils.py +++ b/Scripts/utils.py @@ -1,4 +1,5 @@ import os +import sys import json import plistlib import shutil @@ -217,28 +218,9 @@ class Utils: cols = max(len(line) for line in lines) if lines else 0 print('\033[8;{};{}t'.format(max(rows+6, 30), max(cols+2, 100))) - @staticmethod - def message(text, msg_type="attention"): - # ANSI escape codes for different colors and bold font - RED_BOLD = "\033[1;31m" - YELLOW_BOLD = "\033[1;33m" - CYAN_BOLD = "\033[1;36m" - RESET = "\033[0m" - - if msg_type == "attention": - color_code = RED_BOLD - elif msg_type == "warning": - color_code = YELLOW_BOLD - elif msg_type == "reminder": - color_code = CYAN_BOLD - else: - color_code = RESET - - return "{}{}{}".format(color_code, text, RESET) - - def exit_program(self, custom_content=""): + def exit_program(self): self.head() - print(custom_content) + print("") print("For more information, to report errors, or to contribute to the product:") print("* Facebook: https://www.facebook.com/macforce2601") print("* Telegram: https://t.me/lzhoang2601") @@ -246,4 +228,5 @@ class Utils: print("") print("Thank you for using our program!\n") - exit(0) \ No newline at end of file + self.request_input("Press Enter to exit.") + sys.exit(0) \ No newline at end of file