From 8daec13fbba7d91b4408df6bbf71533f408e7233 Mon Sep 17 00:00:00 2001 From: Syndace Date: Thu, 6 Oct 2022 17:25:37 +0200 Subject: [PATCH] plugin XEP-0384: proper handling of exceptions in `prepare_for_profile` --- sat/plugins/plugin_xep_0384.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/sat/plugins/plugin_xep_0384.py b/sat/plugins/plugin_xep_0384.py index 2fd6f0e9..4cd224ac 100644 --- a/sat/plugins/plugin_xep_0384.py +++ b/sat/plugins/plugin_xep_0384.py @@ -1468,11 +1468,22 @@ class OMEMO: 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