From 770c0ed3a5b0f2f453aa78f7294f971c4814e538 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Fri, 26 Apr 2024 00:41:58 -0400 Subject: [PATCH 1/3] [2203] Catch Irrecoverable Errors --- EDMarketConnector.py | 26 +++++++++++++++++++++++++- L10n/en.template | 6 ++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 09e6fc4e7..8ec3ab755 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -11,9 +11,11 @@ import argparse import html import locale +import os import pathlib import queue import re +import signal import subprocess import sys import threading @@ -2226,7 +2228,29 @@ def test_prop(self): if theme.default_ui_scale is not None: root.tk.call('tk', 'scaling', theme.default_ui_scale * float(ui_scale) / 100.0) - app = AppWindow(root) + try: + app = AppWindow(root) + except Exception as err: + logger.exception(f"EDMC Critical Error: {err}") + title = tr.tl("Error") # LANG: Generic error prefix + message = tr.tl( # LANG: EDMC Critical Error Notification + "EDSM encountered a critical error, and cannot recover. EDMC is shutting down for its own protection!" + ) + err = f"{err.__class__.__name__}: {err}" # type: ignore # hijacking the existing exception detection + detail = tr.tl( # LANG: EDMC Critical Error Details + r"Here's what EDMC Detected:\r\n\r\n{ERR}\r\n\r\nDo you want to file a Bug Report on GitHub?" + ).format(ERR=err) + detail = detail.replace('\\n', '\n') + detail = detail.replace('\\r', '\r') + msg = tk.messagebox.askyesno( + title=title, message=message, detail=detail, icon=tkinter.messagebox.ERROR, type=tkinter.messagebox.YESNO + ) + if msg: + webbrowser.open( + "https://github.com/EDCD/EDMarketConnector/issues/new?" + "assignees=&labels=bug%2C+unconfirmed&projects=&template=bug_report.md&title=" + ) + os.kill(os.getpid(), signal.SIGTERM) def messagebox_broken_plugins(): """Display message about 'broken' plugins that failed to load.""" diff --git a/L10n/en.template b/L10n/en.template index 200743c82..b2c46d7cf 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -36,6 +36,12 @@ /* companion.py: Failed to get Access Token from Frontier Auth service; In files: companion.py:508; */ "Error: unable to get token" = "Error: unable to get token"; +/* EDMarketConnector.py: EDMC Critical Error Notification; */ +"EDSM encountered a critical error, and cannot recover. EDMC is shutting down for its own protection!" = "EDSM encountered a critical error, and cannot recover. EDMC is shutting down for its own protection!"; + +/* EDMarketConnector.py: EDMC Critical Error Details; */ +"Here's what EDMC Detected:\r\n\r\n{ERR}\r\n\r\nDo you want to file a Bug Report on GitHub?" = "Here's what EDMC Detected:\r\n\r\n{ERR}\r\n\r\nDo you want to file a Bug Report on GitHub?"; + /* companion.py: Frontier CAPI returned 418, meaning down for maintenance; In files: companion.py:844; */ "Frontier CAPI down for maintenance" = "Frontier CAPI down for maintenance"; From 8b116516a2238da8268e4b4549138185052d6fcf Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Fri, 26 Apr 2024 00:56:34 -0400 Subject: [PATCH 2/3] [2203] Simplify Duplicate Running Message --- EDMarketConnector.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 8ec3ab755..45bc28c7e 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -338,29 +338,14 @@ def enumwindowsproc(window_handle, l_param): # noqa: CCR001 def already_running_popup(): """Create the "already running" popup.""" - import tkinter as tk - from tkinter import ttk + from tkinter import messagebox # Check for CL arg that suppresses this popup. if args.suppress_dupe_process_popup: sys.exit(0) - root = tk.Tk(className=appname.lower()) - - frame = tk.Frame(root) - frame.grid(row=1, column=0, sticky=tk.NSEW) - - label = tk.Label(frame, text='An EDMarketConnector.exe process was already running, exiting.') - label.grid(row=1, column=0, sticky=tk.NSEW) - - button = ttk.Button(frame, text='OK', command=lambda: sys.exit(0)) - button.grid(row=2, column=0, sticky=tk.S) - - try: - root.mainloop() - except KeyboardInterrupt: - logger.info("Ctrl+C Detected, Attempting Clean Shutdown") - sys.exit() - logger.info('Exiting') + already_running_msg = "An EDMarketConnector process was already running, exiting." + messagebox.showerror(title=appname, message=already_running_msg) + sys.exit(0) journal_lock = JournalLock() locked = journal_lock.obtain_lock() From 3589bdd8e26c506189aa8e3892f1e6435a77f5d8 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Fri, 26 Apr 2024 00:57:23 -0400 Subject: [PATCH 3/3] [Minor] Why Use Two Line When One Line Do Trick --- EDMarketConnector.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 45bc28c7e..92ab3fe8d 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -343,8 +343,7 @@ def already_running_popup(): if args.suppress_dupe_process_popup: sys.exit(0) - already_running_msg = "An EDMarketConnector process was already running, exiting." - messagebox.showerror(title=appname, message=already_running_msg) + messagebox.showerror(title=appname, message="An EDMarketConnector process was already running, exiting.") sys.exit(0) journal_lock = JournalLock()