Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Ease searching for M_TOO_LARGE-related error codes (#10750)
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 authored Sep 6, 2021
1 parent e1641b4 commit 7bb3673
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/10750.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor event size checking code to simplify searching the codebase for the origins of certain error strings that are occasionally emitted.
15 changes: 6 additions & 9 deletions synapse/event_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,18 @@ def check(


def _check_size_limits(event: EventBase) -> None:
def too_big(field):
raise EventSizeError("%s too large" % (field,))

if len(event.user_id) > 255:
too_big("user_id")
raise EventSizeError("'user_id' too large")
if len(event.room_id) > 255:
too_big("room_id")
raise EventSizeError("'room_id' too large")
if event.is_state() and len(event.state_key) > 255:
too_big("state_key")
raise EventSizeError("'state_key' too large")
if len(event.type) > 255:
too_big("type")
raise EventSizeError("'type' too large")
if len(event.event_id) > 255:
too_big("event_id")
raise EventSizeError("'event_id' too large")
if len(encode_canonical_json(event.get_pdu_json())) > MAX_PDU_SIZE:
too_big("event")
raise EventSizeError("event too large")


def _can_federate(event: EventBase, auth_events: StateMap[EventBase]) -> bool:
Expand Down

0 comments on commit 7bb3673

Please sign in to comment.