From 1d7420ed2f10ab6b0df6e1803077087a79fd6721 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 29 Nov 2018 11:32:03 +0000 Subject: [PATCH] Don't log ERROR when no profile exists --- synapse/handlers/federation.py | 2 +- synapse/handlers/room_member.py | 68 ++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 5c6b54721a..19dc6da4a7 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -57,7 +57,7 @@ from synapse.replication.http.federation import ( ) from synapse.replication.http.membership import ReplicationUserJoinedLeftRoomRestServlet from synapse.state import StateResolutionStore, resolve_events_with_store -from synapse.types import UserID, get_domain_from_id, create_requester +from synapse.types import UserID, create_requester, get_domain_from_id from synapse.util import logcontext, unwrapFirstError from synapse.util.async_helpers import Linearizer from synapse.util.distributor import user_joined_room diff --git a/synapse/handlers/room_member.py b/synapse/handlers/room_member.py index f463bb3349..4bf48a507d 100644 --- a/synapse/handlers/room_member.py +++ b/synapse/handlers/room_member.py @@ -28,8 +28,8 @@ from twisted.internet import defer import synapse.server import synapse.types from synapse.api.constants import EventTypes, Membership -from synapse.api.errors import AuthError, Codes, SynapseError -from synapse.types import RoomID, UserID, RoomAlias +from synapse.api.errors import AuthError, Codes, NotFoundError, SynapseError +from synapse.types import RoomAlias, RoomID, UserID from synapse.util import logcontext from synapse.util.async_helpers import Linearizer from synapse.util.distributor import user_joined_room, user_left_room @@ -465,33 +465,47 @@ class RoomMemberHandler(object): @defer.inlineCallbacks def _send_merged_user_invites(self, requester, room_id): try: - profile_alias = "#_profile_" + requester.user.localpart + ":" + self.hs.hostname + profile_alias = "#_profile_%s:%s" % ( + requester.user.localpart, self.hs.hostname, + ) profile_alias = RoomAlias.from_string(profile_alias) - profile_room_id, remote_room_hosts = yield self.lookup_room_alias(profile_alias) - if profile_room_id: - linked_accounts = yield self.state_handler.get_current_state( - room_id=profile_room_id.to_string(), - event_type="m.linked_accounts", - state_key="", + try: + profile_room_id, remote_room_hosts = yield self.lookup_room_alias( + profile_alias, ) - if not linked_accounts or not linked_accounts.content['all_children']: - return - for child_id in linked_accounts.content['all_children']: - child = UserID.from_string(child_id) - if self.hs.is_mine(child) or child_id == requester.user.to_string(): - # TODO: Handle auto-invite for local users (not a priority) - continue - try: - yield self.update_membership( - requester=requester, - target=child, - room_id=room_id, - action="invite", - ) - except Exception: - logger.exception("Failed to invite %s to %s" % (child_id, room_id)) + except NotFoundError: + logger.info( + "Not sending merged invites as %s does not exists", + profile_alias + ) + return + + linked_accounts = yield self.state_handler.get_current_state( + room_id=profile_room_id.to_string(), + event_type="m.linked_accounts", + state_key="", + ) + if not linked_accounts or not linked_accounts.content['all_children']: + return + for child_id in linked_accounts.content['all_children']: + child = UserID.from_string(child_id) + if self.hs.is_mine(child) or child_id == requester.user.to_string(): + # TODO: Handle auto-invite for local users (not a priority) + continue + try: + yield self.update_membership( + requester=requester, + target=child, + room_id=room_id, + action="invite", + ) + except Exception: + logger.exception("Failed to invite %s to %s", child_id, room_id) except Exception: - logger.exception("Failed to send invites to children of %s in %s" % (requester.user.to_string(), room_id)) + logger.exception( + "Failed to send invites to children of %s in %s", + requester.user.to_string(), room_id, + ) @defer.inlineCallbacks def send_membership_event( @@ -619,7 +633,7 @@ class RoomMemberHandler(object): mapping = yield directory_handler.get_association(room_alias) if not mapping: - raise SynapseError(404, "No such room alias") + raise NotFoundError("No such room alias") room_id = mapping["room_id"] servers = mapping["servers"]