From 19beb9d339479475949bdfdb68444b3fc76ee789 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 19 Oct 2026 12:54:21 +0200 Subject: [PATCH] plugin NAT Port: fix errors handling: `miniupnpc` raises `Exception("Success")` when no device is found (instead of returning 0), which was resulting in an exception breaking workflows in Libervia. The code now catches unexpected exceptions, and handles `Exception("Success")` as "no device found". --- .../backend/plugins/plugin_misc_nat_port.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libervia/backend/plugins/plugin_misc_nat_port.py b/libervia/backend/plugins/plugin_misc_nat_port.py index c6e531c0..a3280299 100644 --- a/libervia/backend/plugins/plugin_misc_nat_port.py +++ b/libervia/backend/plugins/plugin_misc_nat_port.py @@ -91,16 +91,23 @@ class NatPort(object): self._upnp = None def _discover(self): - devices = self._upnp.discover() - if devices: + try: + devices = self._upnp.discover() + if not devices: + raise exceptions.NotFound() log.info("{nb} UPnP-IGD device(s) found".format(nb=devices)) - else: + self._upnp.selectigd() + self._external_ip = self._upnp.externalipaddress() + except exceptions.NotFound: log.info("Can't find UPnP-IGD device on the local network") raise failure.Failure(exceptions.NotFound()) - self._upnp.selectigd() - try: - self._external_ip = self._upnp.externalipaddress() - except Exception: + except Exception as e: + # the miniupnpc binding raises Exception("Success") when no device is found, + # instead of returning 0 + if str(e) == "Success": + log.info("Can't find UPnP-IGD device on the local network") + raise failure.Failure(exceptions.NotFound()) + log.warning(f"UPnP-IGD discovery error: {e!r}") raise failure.Failure(exceptions.FeatureNotFound()) def get_ip(self, local=False):