pulb / mailnag

An extensible mail notification daemon
GNU General Public License v2.0
250 stars 32 forks source link

Crash on check internet connection #241

Open vantu5z opened 1 year ago

vantu5z commented 1 year ago

Caught an exception on Mailnag star when internet is not available:

июн 13 09:38:47 vantu5zbook mailnag[1121]: ERROR (2023-06-13 09:38:47): Caught an exception.
                                              Traceback (most recent call last):
                                                File "/usr/lib/python3.11/site-packages/Mailnag/daemon/mailnagdaemon.py", line 165, in _start
                                                  if not self._wait_for_inet_connection():
                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                                File "/usr/lib/python3.11/site-packages/Mailnag/daemon/mailnagdaemon.py", line 212, in _wait_for_inet_connection
                                                  if self._conntest.is_offline():
                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                                File "/usr/lib/python3.11/site-packages/Mailnag/daemon/conntest.py", line 47, in is_offline
                                                  return (not self._monitor.can_reach(Gio.NetworkAddress.new(TEST_HOST, 8080)))
                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                              gi.repository.GLib.GError: g-resolver-error-quark: Ошибка разрешения «www.google.com»: Временный сбой в разрешении имен (1)

To fix this, we can use try like this:

...
            else:
                try:
                    return (not self._monitor.can_reach(Gio.NetworkAddress.new(TEST_HOST, 8080)))
                except:
                    return False
....

About function Gio.NetworkMonitor.can_reach