changeset 3929:42d3110ac9b1

plugin XEP-0384: proper handling of exceptions in `prepare_for_profile`
author Syndace <me@syndace.dev>
date Thu, 06 Oct 2022 17:25:37 +0200
parents 6c36eb30afb8
children 0a6d4168968a
files sat/plugins/plugin_xep_0384.py
diffstat 1 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0384.py	Thu Oct 06 17:22:21 2022 +0200
+++ b/sat/plugins/plugin_xep_0384.py	Thu Oct 06 17:25:37 2022 +0200
@@ -1468,11 +1468,22 @@
             self.__session_manager_waiters[profile] = []
 
             # Build and store the session manager
-            session_manager = await prepare_for_profile(
-                self.__sat,
-                profile,
-                initial_own_label="Libervia"
-            )
+            try:
+                session_manager = await prepare_for_profile(
+                    self.__sat,
+                    profile,
+                    initial_own_label="Libervia"
+                )
+            except Exception as e:
+                # In case of an error during initalization, notify the waiters accordingly
+                # and delete them
+                for waiter in self.__session_manager_waiters[profile]:
+                    waiter.errback(e)
+                del self.__session_manager_waiters[profile]
+
+                # Re-raise the exception
+                raise
+
             self.__session_managers[profile] = session_manager
 
             # Notify the waiters and delete them