Display error message dialog on Windows for startup errors

This commit is contained in:
shortcutme 2019-07-17 16:31:32 +02:00
parent 149278abd0
commit 9526424a47
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 28 additions and 1 deletions

View File

@ -26,7 +26,12 @@ def main():
print("Failed to log error:", log_err)
traceback.print_exc()
from Config import config
traceback.print_exc(file=open(config.log_dir + "/error.log", "a"))
error_log_path = config.log_dir + "/error.log"
traceback.print_exc(file=open(error_log_path, "w"))
print("---")
print("Please report it: https://github.com/HelloZeroNet/ZeroNet/issues/new?assignees=&labels=&template=bug-report.md")
if sys.platform.startswith("win"):
displayErrorMessage(err, error_log_path)
if main and (main.update_after_shutdown or main.restart_after_shutdown): # Updater
if main.update_after_shutdown:
@ -37,6 +42,28 @@ def main():
print("Restarting...")
restart()
def displayErrorMessage(err, error_log_path):
import ctypes
import urllib.parse
import subprocess
MB_YESNOCANCEL = 0x3
MB_ICONEXCLAIMATION = 0x30
ID_YES = 0x6
ID_NO = 0x7
ID_CANCEL = 0x2
err_message = "%s: %s" % (type(err).__name__, err)
res = ctypes.windll.user32.MessageBoxW(0, "Unhandled exception: %s\nReport error?" % err_message, "ZeroNet error", MB_YESNOCANCEL | MB_ICONEXCLAIMATION)
if res == ID_YES:
import webbrowser
report_url = "https://github.com/HelloZeroNet/ZeroNet/issues/new?assignees=&labels=&template=bug-report.md&title=%s"
webbrowser.open(report_url % urllib.parse.quote("Unhandled exception: %s" % err_message))
if res in [ID_YES, ID_NO]:
subprocess.Popen(['notepad.exe', error_log_path])
def restart():
if "main" in sys.modules: