From 7bb3673f37d02d8bcda586daaac3334aebe81195 Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Mon, 6 Sep 2021 14:35:56 +0100 Subject: [PATCH] Ease searching for M_TOO_LARGE-related error codes (#10750) --- changelog.d/10750.misc | 1 + synapse/event_auth.py | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 changelog.d/10750.misc diff --git a/changelog.d/10750.misc b/changelog.d/10750.misc new file mode 100644 index 000000000..ded5cf626 --- /dev/null +++ b/changelog.d/10750.misc @@ -0,0 +1 @@ +Refactor event size checking code to simplify searching the codebase for the origins of certain error strings that are occasionally emitted. \ No newline at end of file diff --git a/synapse/event_auth.py b/synapse/event_auth.py index c3a0c1049..b63a1afe9 100644 --- a/synapse/event_auth.py +++ b/synapse/event_auth.py @@ -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: