From 9daf552477e8c7dd19de4542dcdfeeac16c633bb Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Mon, 11 Oct 2021 14:02:14 +0100 Subject: [PATCH 1/4] Pass through `SynapseError`s raised from `check_event_allowed` Signed-off-by: Olivier Wilkinson (reivilibre) --- synapse/events/third_party_rules.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/synapse/events/third_party_rules.py b/synapse/events/third_party_rules.py index d94b1bb4d275..a192feab13b9 100644 --- a/synapse/events/third_party_rules.py +++ b/synapse/events/third_party_rules.py @@ -217,6 +217,15 @@ async def check_event_allowed( for callback in self._check_event_allowed_callbacks: try: res, replacement_data = await callback(event, state_events) + except SynapseError as e: + # HACK. Being able to throw SynapseErrors is relied upon by + # some modules. PR #10386 accidentally broke this ability. + # That said, we aren't keen on exposing this implementation detail + # to modules and we should one day have a proper way to do what + # is wanted. + # This module API callback needs a rework so that hacks such as + # this one are not necessary. + raise e except Exception as e: logger.warning("Failed to run module API callback %s: %s", callback, e) continue From 19b4331f36b237ce92241e1456f689999524c943 Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Mon, 11 Oct 2021 14:02:20 +0100 Subject: [PATCH 2/4] Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) --- changelog.d/11042.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/11042.bugfix diff --git a/changelog.d/11042.bugfix b/changelog.d/11042.bugfix new file mode 100644 index 000000000000..34e11b0fa4d4 --- /dev/null +++ b/changelog.d/11042.bugfix @@ -0,0 +1 @@ +Work around a regression in the experimental Module API callback `check_event_allowed` that caused raised `SynapseError`s to be ignored. From 7856a807565bb85e5e825fe47c6f552e2b05218f Mon Sep 17 00:00:00 2001 From: "Olivier Wilkinson (reivilibre)" Date: Mon, 11 Oct 2021 14:06:05 +0100 Subject: [PATCH 3/4] Tweak Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) --- changelog.d/11042.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/11042.bugfix b/changelog.d/11042.bugfix index 34e11b0fa4d4..598da0fc888f 100644 --- a/changelog.d/11042.bugfix +++ b/changelog.d/11042.bugfix @@ -1 +1 @@ -Work around a regression in the experimental Module API callback `check_event_allowed` that caused raised `SynapseError`s to be ignored. +Work around a regression, introduced in Synapse 1.39.0, that caused `SynapseError`s raised by the experimental Module API callback `check_event_allowed` to be ignored. From c3314ae4ad8aeac458f05160c70a81b083613629 Mon Sep 17 00:00:00 2001 From: reivilibre Date: Mon, 11 Oct 2021 14:53:42 +0100 Subject: [PATCH 4/4] Apply phrasing suggestions from code review Co-authored-by: Brendan Abolivier --- changelog.d/11042.bugfix | 2 +- synapse/events/third_party_rules.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/changelog.d/11042.bugfix b/changelog.d/11042.bugfix index 598da0fc888f..536c47417d49 100644 --- a/changelog.d/11042.bugfix +++ b/changelog.d/11042.bugfix @@ -1 +1 @@ -Work around a regression, introduced in Synapse 1.39.0, that caused `SynapseError`s raised by the experimental Module API callback `check_event_allowed` to be ignored. +Work around a regression, introduced in Synapse 1.39.0, that caused `SynapseError`s raised by the experimental third-party rules module callback `check_event_allowed` to be ignored. diff --git a/synapse/events/third_party_rules.py b/synapse/events/third_party_rules.py index a192feab13b9..976d9fa4468d 100644 --- a/synapse/events/third_party_rules.py +++ b/synapse/events/third_party_rules.py @@ -218,12 +218,12 @@ async def check_event_allowed( try: res, replacement_data = await callback(event, state_events) except SynapseError as e: - # HACK. Being able to throw SynapseErrors is relied upon by + # FIXME: Being able to throw SynapseErrors is relied upon by # some modules. PR #10386 accidentally broke this ability. # That said, we aren't keen on exposing this implementation detail # to modules and we should one day have a proper way to do what # is wanted. - # This module API callback needs a rework so that hacks such as + # This module callback needs a rework so that hacks such as # this one are not necessary. raise e except Exception as e: