raise instead of overwriting the config file on syntax error
This commit is contained in:
@@ -27,7 +27,7 @@ import os
|
||||
import signal
|
||||
import sys
|
||||
import threading
|
||||
from typing import Optional, TYPE_CHECKING, List, Sequence
|
||||
from typing import Optional, TYPE_CHECKING, List, Sequence, Union
|
||||
|
||||
try:
|
||||
import PyQt6
|
||||
@@ -582,3 +582,25 @@ class ElectrumGui(BaseElectrumGui, Logger):
|
||||
message = _("Text copied to Clipboard") if title is None else _("{} copied to Clipboard").format(title)
|
||||
# tooltip cannot be displayed immediately when called from a menu; wait 200ms
|
||||
self.timer.singleShot(200, lambda: QToolTip.showText(QCursor.pos(), message, None))
|
||||
|
||||
|
||||
def standalone_exception_dialog(exception: Union[str, BaseException]) -> None:
|
||||
app = QApplication.instance()
|
||||
if not app:
|
||||
app = QApplication([])
|
||||
|
||||
msg_box = QMessageBox()
|
||||
msg_box.setWindowTitle(_("Error starting Electrum"))
|
||||
msg_box.setIcon(QMessageBox.Icon.Critical)
|
||||
msg_box.setText(_("An error occurred") + ":")
|
||||
msg_box.setInformativeText(str(exception))
|
||||
|
||||
# Add detailed traceback if available
|
||||
if hasattr(exception, "__traceback__"):
|
||||
import traceback
|
||||
detailed_text = ''.join(traceback.format_exception(
|
||||
type(exception), exception, exception.__traceback__)
|
||||
)
|
||||
msg_box.setDetailedText(detailed_text)
|
||||
|
||||
msg_box.exec()
|
||||
|
||||
@@ -900,9 +900,7 @@ def read_user_config(path: Optional[str]) -> Dict[str, Any]:
|
||||
with open(config_path, "r", encoding='utf-8') as f:
|
||||
data = f.read()
|
||||
result = json.loads(data)
|
||||
except Exception as exc:
|
||||
_logger.warning(f"Cannot read config file at {config_path}: {exc}")
|
||||
return {}
|
||||
if not type(result) is dict:
|
||||
return {}
|
||||
assert isinstance(result, dict), "config file is not a dict"
|
||||
except Exception as e:
|
||||
raise ValueError(f"Invalid config file at {config_path}: {str(e)}")
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user