Skip to content

Commit e92686d

Browse files
authored
Adds better unhandled exception dialog during project sync (#799)
1 parent b0ba366 commit e92686d

File tree

2 files changed

+48
-26
lines changed

2 files changed

+48
-26
lines changed

Mergin/projects_manager.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ def create_project(self, project_name, project_dir, is_public, namespace):
181181
unhandled_exception_message(
182182
dlg.exception_details(),
183183
"Project sync",
184-
f"Failed to sync project {project_name} due to an unhandled exception.",
184+
f"Something went wrong while synchronising your project {project_name}.",
185+
self.mc,
185186
)
186187
return True
187188

@@ -375,7 +376,8 @@ def sync_project(self, project_dir, project_name=None):
375376
unhandled_exception_message(
376377
dlg.exception_details(),
377378
"Project sync",
378-
f"Failed to sync project {project_name} due to an unhandled exception.",
379+
f"Something went wrong while synchronising your project {project_name}.",
380+
self.mc,
379381
)
380382
return
381383

@@ -438,7 +440,8 @@ def sync_project(self, project_dir, project_name=None):
438440
unhandled_exception_message(
439441
dlg.exception_details(),
440442
"Project sync",
441-
f"Failed to sync project {project_name} due to an unhandled exception.",
443+
f"Something went wrong while synchronising your project {project_name}.",
444+
self.mc,
442445
)
443446
return
444447

@@ -580,9 +583,9 @@ def download_project(self, project):
580583
unhandled_exception_message(
581584
dlg.exception_details(),
582585
"Project download",
583-
f"Failed to download project {project_name} due to an unhandled exception.",
586+
f"Something went wrong while downloading your project {project_name}.",
587+
self.mc,
584588
dlg.log_file,
585-
self.mc.username(),
586589
)
587590
return
588591
if not dlg.is_complete:

Mergin/utils.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from urllib.error import URLError, HTTPError
88
import configparser
99
import os
10+
import webbrowser
1011
from osgeo import gdal
1112
import pathlib
1213
import platform
@@ -18,7 +19,7 @@
1819
import re
1920

2021
from qgis.PyQt.QtCore import QSettings, QVariant
21-
from qgis.PyQt.QtWidgets import QMessageBox, QFileDialog
22+
from qgis.PyQt.QtWidgets import QMessageBox, QFileDialog, QCheckBox
2223
from qgis.PyQt.QtGui import QPalette, QColor, QIcon
2324
from qgis.PyQt.QtXml import QDomDocument
2425
from qgis.core import (
@@ -861,30 +862,48 @@ def login_error_message(e):
861862
QMessageBox.critical(None, "Login failed", msg, QMessageBox.StandardButton.Close)
862863

863864

864-
def unhandled_exception_message(error_details, dialog_title, error_text, log_file=None, username=None):
865-
msg = (
866-
error_text + "<p>This should not happen, "
867-
'<a href="https://github.com/MerginMaps/qgis-mergin-plugin/issues">'
868-
"please report the problem</a>."
869-
)
865+
def unhandled_exception_message(error_details, dialog_title, error_text, mm_client, log_file=None):
870866
box = QMessageBox()
871867
box.setIcon(QMessageBox.Icon.Critical)
872868
box.setWindowTitle(dialog_title)
873-
box.setText(msg)
874-
if log_file is None:
875-
box.setDetailedText(error_details)
876-
else:
877-
error_details = (
878-
"An error occured during project synchronisation. The log was saved to "
879-
f"{log_file}. Click 'Send logs' to send a diagnostic log to the developers "
880-
"to help them determine the exact cause of the problem.\n\n"
881-
"The log does not contain any of your data, only file names. "
882-
"It would be useful if you also send a mail to support@merginmaps.com "
883-
"and briefly describe the problem to add more context to the diagnostic log."
869+
box.setText(error_text)
870+
box.setInformativeText(
871+
"An unexpected error occurred. "
872+
"You can help us fix it by reporting the problem. "
873+
"Click the button below to create a report we can review."
874+
)
875+
876+
if log_file:
877+
check = QCheckBox("Include diagnostic log (what is this?)")
878+
check.setChecked(True)
879+
check.setToolTip(
880+
"The diagnostic log contains only file names and activity steps that "
881+
"help us understand what went wrong. It does not include your data."
882+
)
883+
884+
box.setCheckBox(check)
885+
886+
error_details = f"The diagnostic log is saved here: {log_file}.\n\n" f"Error details:\n{error_details}"
887+
888+
box.setDetailedText(error_details)
889+
username = mm_client.username() if mm_client else "Unknown"
890+
891+
email_subject = "Problem with sync from QGIS"
892+
email_body = (
893+
"Hi,\n"
894+
"I encountered an issue during synchronisation. (Please add more details here).\n\n"
895+
f"Problem: {error_text}\n"
896+
f"Username: {username}\n"
897+
f"{error_details}"
898+
)
899+
900+
btn = box.addButton("Report problem", QMessageBox.ButtonRole.HelpRole)
901+
btn.clicked.connect(
902+
lambda: (
903+
send_logs(mm_client, log_file) if box.checkBox() and box.checkBox().isChecked() else None,
904+
webbrowser.open(f"mailto:support@merginmaps.com?subject={email_subject}&body={email_body}"),
884905
)
885-
box.setDetailedText(error_details)
886-
btn = box.addButton("Send logs", QMessageBox.ButtonRole.ActionRole)
887-
btn.clicked.connect(lambda: send_logs(username, log_file))
906+
)
888907
box.exec()
889908

890909

0 commit comments

Comments
 (0)