comparison sat/plugins/plugin_xep_0384.py @ 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 7b2c51bcc8f5
children cecf45416403
comparison
equal deleted inserted replaced
3928:6c36eb30afb8 3929:42d3110ac9b1
1466 1466
1467 # If the session manager is not being built, do so here. 1467 # If the session manager is not being built, do so here.
1468 self.__session_manager_waiters[profile] = [] 1468 self.__session_manager_waiters[profile] = []
1469 1469
1470 # Build and store the session manager 1470 # Build and store the session manager
1471 session_manager = await prepare_for_profile( 1471 try:
1472 self.__sat, 1472 session_manager = await prepare_for_profile(
1473 profile, 1473 self.__sat,
1474 initial_own_label="Libervia" 1474 profile,
1475 ) 1475 initial_own_label="Libervia"
1476 )
1477 except Exception as e:
1478 # In case of an error during initalization, notify the waiters accordingly
1479 # and delete them
1480 for waiter in self.__session_manager_waiters[profile]:
1481 waiter.errback(e)
1482 del self.__session_manager_waiters[profile]
1483
1484 # Re-raise the exception
1485 raise
1486
1476 self.__session_managers[profile] = session_manager 1487 self.__session_managers[profile] = session_manager
1477 1488
1478 # Notify the waiters and delete them 1489 # Notify the waiters and delete them
1479 for waiter in self.__session_manager_waiters[profile]: 1490 for waiter in self.__session_manager_waiters[profile]:
1480 waiter.callback(session_manager) 1491 waiter.callback(session_manager)