1
0

qml: qenetwork: fix type confusion for "server"

exc triggered when switching from same server to same server:
```
  9.43 | D | gui.qml.qenetwork | server_status updated: Connecting
  9.43 | E | network | Exception in _run_new_interface: Exception('diagnostic name not yet available?')
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/logging.py", line 241, in __get_logger_for_obj
    diag_name = self.diagnostic_name()
  File "/home/user/wspace/electrum/electrum/interface.py", line 555, in diagnostic_name
    return self.server.net_addr_str()
AttributeError: 'str' object has no attribute 'net_addr_str'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/util.py", line 1218, in wrapper
    return await func(*args, **kwargs)
  File "/home/user/wspace/electrum/electrum/network.py", line 986, in _run_new_interface
    interface = Interface(network=self, server=server)
  File "/home/user/wspace/electrum/electrum/interface.py", line 502, in __init__
    Logger.__init__(self)
  File "/home/user/wspace/electrum/electrum/logging.py", line 232, in __init__
    self.logger = self.__get_logger_for_obj()
  File "/home/user/wspace/electrum/electrum/logging.py", line 243, in __get_logger_for_obj
    raise Exception("diagnostic name not yet available?") from e
Exception: diagnostic name not yet available?
```
This commit is contained in:
SomberNight
2025-07-18 14:16:30 +00:00
parent 159d83905b
commit eef562389c
4 changed files with 9 additions and 8 deletions

View File

@@ -207,16 +207,13 @@ class QENetwork(QObject, QtEventListener):
return self._server
@pyqtSlot(str, bool, bool)
def setServerParameters(self, server: str, auto_connect: bool, one_server: bool):
def setServerParameters(self, server_str: str, auto_connect: bool, one_server: bool):
net_params = self.network.get_parameters()
server = ServerAddr.from_str_with_inference(server_str)
if server == net_params.server and auto_connect == net_params.auto_connect and one_server == net_params.oneserver:
return
if server != str(net_params.server):
try:
server = ServerAddr.from_str_with_inference(server)
if not server:
raise Exception('failed to parse')
except Exception:
if server != net_params.server:
if server is None:
if not auto_connect:
return
server = net_params.server

View File

@@ -462,7 +462,7 @@ class ServerWidget(QWidget, QtEventListener):
if not self.network._was_started:
self.update()
return
server = self.server_e.text().strip()
server = ServerAddr.from_str_with_inference(self.server_e.text().strip())
net_params = self.network.get_parameters()
if server != net_params.server or self.is_auto_connect() != net_params.auto_connect or self.is_one_server() != net_params.oneserver:
self.set_server()

View File

@@ -496,6 +496,7 @@ def _get_cert_path_for_host(*, config: 'SimpleConfig', host: str) -> str:
class Interface(Logger):
def __init__(self, *, network: 'Network', server: ServerAddr):
assert isinstance(server, ServerAddr), f"expected ServerAddr, got {type(server)}"
self.ready = network.asyncio_loop.create_future()
self.got_disconnected = asyncio.Event()
self.server = server

View File

@@ -886,6 +886,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
queue interface to be started. The actual switch will
happen when the interface becomes ready.
"""
assert isinstance(server, ServerAddr), f"expected ServerAddr, got {type(server)}"
self.default_server = server
old_interface = self.interface
old_server = old_interface.server if old_interface else None
@@ -973,6 +974,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
@ignore_exceptions # do not kill outer taskgroup
@log_exceptions
async def _run_new_interface(self, server: ServerAddr):
assert isinstance(server, ServerAddr), f"expected ServerAddr, got {type(server)}"
if (server in self.interfaces
or server in self._connecting_ifaces
or server in self._closing_ifaces):
@@ -1508,6 +1510,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
# FIXME this should try to honour "healthy spread of connected servers"
server = self._get_next_server_to_try()
if server:
assert isinstance(server, ServerAddr), f"expected ServerAddr, got {type(server)}"
await self.taskgroup.spawn(self._run_new_interface(server))
async def maintain_healthy_spread_of_connected_servers():
with self.interfaces_lock: interfaces = list(self.interfaces.values())