Don't log ERROR when no profile exists

This commit is contained in:
Erik Johnston 2018-11-29 11:32:03 +00:00 committed by Brendan Abolivier
parent a527fbaae6
commit 1d7420ed2f
2 changed files with 42 additions and 28 deletions

View file

@ -57,7 +57,7 @@ from synapse.replication.http.federation import (
) )
from synapse.replication.http.membership import ReplicationUserJoinedLeftRoomRestServlet from synapse.replication.http.membership import ReplicationUserJoinedLeftRoomRestServlet
from synapse.state import StateResolutionStore, resolve_events_with_store 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 import logcontext, unwrapFirstError
from synapse.util.async_helpers import Linearizer from synapse.util.async_helpers import Linearizer
from synapse.util.distributor import user_joined_room from synapse.util.distributor import user_joined_room

View file

@ -28,8 +28,8 @@ from twisted.internet import defer
import synapse.server import synapse.server
import synapse.types import synapse.types
from synapse.api.constants import EventTypes, Membership from synapse.api.constants import EventTypes, Membership
from synapse.api.errors import AuthError, Codes, SynapseError from synapse.api.errors import AuthError, Codes, NotFoundError, SynapseError
from synapse.types import RoomID, UserID, RoomAlias from synapse.types import RoomAlias, RoomID, UserID
from synapse.util import logcontext from synapse.util import logcontext
from synapse.util.async_helpers import Linearizer from synapse.util.async_helpers import Linearizer
from synapse.util.distributor import user_joined_room, user_left_room from synapse.util.distributor import user_joined_room, user_left_room
@ -465,33 +465,47 @@ class RoomMemberHandler(object):
@defer.inlineCallbacks @defer.inlineCallbacks
def _send_merged_user_invites(self, requester, room_id): def _send_merged_user_invites(self, requester, room_id):
try: 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_alias = RoomAlias.from_string(profile_alias)
profile_room_id, remote_room_hosts = yield self.lookup_room_alias(profile_alias) try:
if profile_room_id: profile_room_id, remote_room_hosts = yield self.lookup_room_alias(
linked_accounts = yield self.state_handler.get_current_state( profile_alias,
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']: except NotFoundError:
return logger.info(
for child_id in linked_accounts.content['all_children']: "Not sending merged invites as %s does not exists",
child = UserID.from_string(child_id) profile_alias
if self.hs.is_mine(child) or child_id == requester.user.to_string(): )
# TODO: Handle auto-invite for local users (not a priority) return
continue
try: linked_accounts = yield self.state_handler.get_current_state(
yield self.update_membership( room_id=profile_room_id.to_string(),
requester=requester, event_type="m.linked_accounts",
target=child, state_key="",
room_id=room_id, )
action="invite", if not linked_accounts or not linked_accounts.content['all_children']:
) return
except Exception: for child_id in linked_accounts.content['all_children']:
logger.exception("Failed to invite %s to %s" % (child_id, room_id)) 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: 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 @defer.inlineCallbacks
def send_membership_event( def send_membership_event(
@ -619,7 +633,7 @@ class RoomMemberHandler(object):
mapping = yield directory_handler.get_association(room_alias) mapping = yield directory_handler.get_association(room_alias)
if not mapping: if not mapping:
raise SynapseError(404, "No such room alias") raise NotFoundError("No such room alias")
room_id = mapping["room_id"] room_id = mapping["room_id"]
servers = mapping["servers"] servers = mapping["servers"]