Update public source

This commit is contained in:
2026-10-16 16:23:12 +03:00
parent 09198e5ab3
commit 1a38d37368
+71 -9
View File
@@ -36,6 +36,8 @@ class UnsupportedSecurityError(WiFiConnectionError):
class NetworkRestoreError(WiFiConnectionError): class NetworkRestoreError(WiFiConnectionError):
pass pass
class NetworkCleanupError(WiFiConnectionError):
pass
@dataclass(frozen=True) @dataclass(frozen=True)
@@ -495,6 +497,8 @@ class WiFiConnectionService:
*arguments *arguments
) )
try:
output = self._nmcli( output = self._nmcli(
"--get-values", "--get-values",
"connection.uuid", "connection.uuid",
@@ -511,6 +515,27 @@ class WiFiConnectionService:
"NetworkManager created a profile but returned an invalid UUID." "NetworkManager created a profile but returned an invalid UUID."
) )
except Exception as error:
try:
self._nmcli(
"connection",
"delete",
"id",
profile_name
)
except NetworkCommandError as cleanup_error:
raise WiFiConnectionError(
"NetworkManager created a temporary profile, but its UUID "
"could not be obtained and the profile could not be deleted: "
f"{cleanup_error}"
) from error
raise
return output return output
@staticmethod @staticmethod
@@ -644,8 +669,6 @@ class WiFiConnectionService:
if not profile_uuid: if not profile_uuid:
return return
try:
self._nmcli( self._nmcli(
"connection", "connection",
"delete", "delete",
@@ -653,9 +676,6 @@ class WiFiConnectionService:
profile_uuid profile_uuid
) )
except NetworkCommandError:
pass
def connect( def connect(
self, self,
interface, interface,
@@ -682,12 +702,22 @@ class WiFiConnectionService:
password password
) )
except Exception: except Exception as connection_error:
try:
self._delete_profile( self._delete_profile(
profile_uuid profile_uuid
) )
except NetworkCommandError as cleanup_error:
raise NetworkCleanupError(
"Wi-Fi connection failed: "
f"{connection_error}. The temporary profile could not be deleted: "
f"{cleanup_error}"
) from connection_error
raise raise
return { return {
@@ -729,6 +759,7 @@ class WiFiConnectionService:
success = False success = False
error_message = None error_message = None
restore_error = None restore_error = None
cleanup_error = None
try: try:
@@ -781,8 +812,12 @@ class WiFiConnectionService:
profile_uuid profile_uuid
) )
except NetworkCommandError: except NetworkCommandError as error:
pass
if success:
restore_error = str(
error
)
except NetworkCommandError as error: except NetworkCommandError as error:
@@ -790,12 +825,26 @@ class WiFiConnectionService:
error error
) )
finally: try:
self._delete_profile( self._delete_profile(
profile_uuid profile_uuid
) )
except NetworkCommandError as error:
cleanup_error = str(
error
)
if restore_error and cleanup_error:
raise NetworkRestoreError(
"The Wi-Fi verification attempt finished, but the previous connection "
f"could not be restored: {restore_error}. "
f"The temporary profile could not be deleted: {cleanup_error}"
)
if restore_error: if restore_error:
raise NetworkRestoreError( raise NetworkRestoreError(
@@ -803,6 +852,19 @@ class WiFiConnectionService:
f"could not be restored: {restore_error}" f"could not be restored: {restore_error}"
) )
if cleanup_error:
verification_error = (
f"Password verification failed: {error_message}. "
if error_message else ""
)
raise NetworkCleanupError(
f"{verification_error}"
"The temporary Wi-Fi profile could not be deleted: "
f"{cleanup_error}"
)
return { return {
"success": success, "success": success,
"interface": interface, "interface": interface,