5252from typing_extensions import ParamSpec
5353
5454from twisted .internet import defer , threads
55+ from twisted .python .failure import Failure
5556from twisted .python .threadpool import ThreadPool
5657
5758from synapse .logging .loggers import ExplicitlyConfiguredLogger
@@ -963,6 +964,12 @@ def _log_set_context_cb(
963964 context ,
964965 )
965966 set_current_context (context )
967+
968+ # Re-raise the exception so that any further errbacks can do their thing as
969+ # normal
970+ if isinstance (result , Failure ):
971+ result .raiseException ()
972+ # Otherwise, pass the result through
966973 return result
967974
968975 d .addBoth (_log_set_context_cb , SENTINEL_CONTEXT )
@@ -1069,6 +1076,12 @@ def _log_set_context_cb(
10691076 context ,
10701077 )
10711078 set_current_context (context )
1079+
1080+ # Re-raise the exception so that any further errbacks can do their thing as
1081+ # normal
1082+ if isinstance (result , Failure ):
1083+ result .raiseException ()
1084+ # Otherwise, pass the result through
10721085 return result
10731086
10741087 deferred .addBoth (_log_set_context_cb , calling_context )
@@ -1082,8 +1095,17 @@ def _log_set_context_cb(
10821095
10831096
10841097def _set_context_cb (result : ResultT , context : LoggingContextOrSentinel ) -> ResultT :
1085- """A callback function which just sets the logging context"""
1098+ """
1099+ A transparent passthrough deferred callback/errback which sets the logging context
1100+ """
10861101 set_current_context (context )
1102+
1103+ # Re-raise the exception so that any further errbacks can do their thing as
1104+ # normal
1105+ if isinstance (result , Failure ):
1106+ result .raiseException ()
1107+
1108+ # Otherwise, pass the result through
10871109 return result
10881110
10891111
0 commit comments