[Console] Fix incorrect test for when a host is online

The tests in connectionmanager for when a host is online are broken
and always considers a host as online.

When an error occurs in e.g. in _on_connect_fail, report_message()
in PopupsHandler expects the message to be string, not a Twisted Failure.
Fix by checking if message is string and log a warning before converting
to string.

Closes: https://github.com/deluge-torrent/deluge/pull/277
This commit is contained in:
bendikro 2020-04-02 22:02:00 +01:00 committed by Calum Lind
parent 29f0789223
commit 66b5a2fc40
No known key found for this signature in database
GPG key ID: 90597A687B836BA3
2 changed files with 20 additions and 13 deletions

View file

@ -30,9 +30,12 @@ class ConnectionManager(BaseMode, PopupsHandler):
self.all_torrents = None
self.hostlist = HostList()
BaseMode.__init__(self, stdscr, encoding=encoding)
self.update_hosts_status()
def update_select_host_popup(self):
if self.popup and not isinstance(self.popup, SelectablePopup):
# Ignore MessagePopup on popup stack upon connect fail
return
selected_index = self.popup.current_selection() if self.popup else None
popup = SelectablePopup(
@ -47,22 +50,24 @@ class ConnectionManager(BaseMode, PopupsHandler):
% (_('Quit'), _('Add Host'), _('Delete Host')),
space_below=True,
)
self.push_popup(popup, clear=True)
for host_entry in self.hostlist.get_hosts_info():
host_id, hostname, port, user = host_entry
args = {'data': host_id, 'foreground': 'red'}
state = 'Offline'
if host_id in self.statuses:
state = 'Online'
args.update({'data': self.statuses[host_id], 'foreground': 'green'})
host_str = '%s:%d [%s]' % (hostname, port, state)
self.popup.add_line(
host_status = self.statuses.get(host_id)
state = host_status[1] if host_status else 'Offline'
state_color = 'green' if state in ('Online', 'Connected') else 'red'
host_str = f'{hostname}:{port} [{state}]'
args = {'data': host_id, 'foreground': state_color}
popup.add_line(
host_id, host_str, selectable=True, use_underline=True, **args
)
if selected_index:
self.popup.set_selection(selected_index)
popup.set_selection(selected_index)
self.push_popup(popup, clear=True)
self.inlist = True
self.refresh()
@ -82,7 +87,7 @@ class ConnectionManager(BaseMode, PopupsHandler):
d.addCallback(on_console_start)
def _on_connect_fail(self, result):
self.report_message('Failed to connect!', result)
self.report_message('Failed to connect!', result.getErrorMessage())
self.refresh()
if hasattr(result, 'getTraceback'):
log.exception(result)
@ -164,7 +169,9 @@ class ConnectionManager(BaseMode, PopupsHandler):
if not self.popup:
self.update_select_host_popup()
self.popup.refresh()
if self.popup:
self.popup.refresh()
curses.doupdate()
@overrides(BaseMode)

View file

@ -218,7 +218,7 @@ class HostList:
try:
ip = gethostbyname(host)
except gaierror as ex:
log.error('Error resolving host %s to ip: %s', host, ex.args[1])
log.warning('Unable to resolve host %s to IP: %s', host, ex.args[1])
return defer.succeed(status_offline)
host_conn_info = (