Skip to content

Commit dc39978

Browse files
authored
fix: Add exception logging to Stream.trigger (#6902)
1 parent c4d1663 commit dc39978

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

holoviews/streams.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,23 @@ def trigger(cls, streams):
242242
)
243243

244244
with triggering_streams(streams):
245+
errors = []
245246
for subscriber in subscribers:
246-
subscriber(**dict(union))
247+
try:
248+
subscriber(**dict(union))
249+
except Exception as e:
250+
errors.append(e)
251+
252+
# Re-raise a single error directly to preserve its original exception
253+
# type e.g. AbbreviatedException.
254+
# NOTE: With Python 3.11 we can use an ExceptionGroup.
255+
if len(errors) == 1:
256+
raise errors[0]
257+
elif errors:
258+
raise RuntimeError(
259+
f"{len(errors)} stream subscribers raised an exception. "
260+
"All subscribers were invoked regardless."
261+
) from Exception(*errors)
247262

248263
for stream in streams:
249264
with util.disable_constant(stream):

holoviews/tests/test_streams.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,26 @@ def test_explicit_parameter(self):
160160
assert self.ExplicitTest.param["test"].default == 42
161161
assert self.ExplicitTest.param["test"].doc == "Test docstring"
162162

163+
def test_subscriber_error_logging_isolation(self):
164+
xy = self.XY()
165+
calls = []
166+
167+
def bad_subscriber(**kw):
168+
calls.append("bad")
169+
raise RuntimeError("bad subscriber")
170+
171+
def good_subscriber(**kw):
172+
calls.append("good")
173+
174+
xy.add_subscriber(bad_subscriber)
175+
xy.add_subscriber(good_subscriber)
176+
177+
with pytest.raises(RuntimeError, match="bad subscriber"):
178+
Stream.trigger([xy])
179+
180+
assert len(calls) == 2
181+
assert calls == ["bad", "good"]
182+
163183

164184
class _Subscriber:
165185
def __init__(self, cb=None):

0 commit comments

Comments
 (0)