Skip to content

Commit f1394d3

Browse files
committed
Add new error symbol to catch subscriber errors
* jupyter-monads.el (jupyter-publisher-subscribers-had-errors): The new symbol. (jupyter-pseudo-bind-content): Store subscriber errors as they happen and raise a `jupyter-publisher-subscribers-had-errors` error passing the list of errors after processing all subscribers.
1 parent c3c21e4 commit f1394d3

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

jupyter-monads.el

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,26 +179,41 @@ result of this function to cancel its subscription with the
179179
publisher providing content."
180180
(list 'unsubscribe))
181181

182+
(define-error 'jupyter-publisher-subscribers-had-errors
183+
"Publisher's subscribers had errors")
184+
182185
(defun jupyter-pseudo-bind-content (pub-fn content subs)
183186
"Apply PUB-FN on submitted CONTENT to produce published content.
184187
Call each subscriber in SUBS on the published content. Remove
185188
those subscribers that cancel their subscription.
186189
187-
Errors signaled by a subscriber are demoted to messages."
190+
When a subscriber signals an error it is noted and the remaining
191+
subscribers are processed. After processing all subscribers, a
192+
`jupyter-publisher-errors' error is raised with the data being
193+
the list of errors raised when calling subscribers. Note, when a
194+
subscriber errors, it remains in the list of subscribers."
188195
(pcase (funcall pub-fn content)
189196
((and `(content ,_) sub-content)
190197
;; NOTE: The first element of SUBS is ignored here so that the
191198
;; pointer to the subscriber list remains the same for each
192199
;; publisher, even when subscribers are being destructively
193200
;; removed.
194-
(while (cadr subs)
195-
(with-demoted-errors "Jupyter: I/O subscriber error: %S"
196-
;; Publish subscriber content to subscribers
197-
(pcase (funcall (cadr subs) sub-content)
198-
;; Destructively remove the subscriber when it returns an
199-
;; unsubscribe value.
200-
('(unsubscribe) (setcdr subs (cddr subs)))
201-
(_ (pop subs)))))
201+
(let ((errors nil))
202+
(while (cadr subs)
203+
(condition-case err
204+
;; Publish subscriber content to subscribers
205+
(pcase (funcall (cadr subs) sub-content)
206+
;; Destructively remove the subscriber when it returns an
207+
;; unsubscribe value.
208+
('(unsubscribe) (setcdr subs (cddr subs)))
209+
(_ (pop subs)))
210+
(error
211+
;; Skip over any subscribers that raised an error.
212+
(pop subs)
213+
(push err errors))))
214+
;; Inform about the errors.
215+
(when errors
216+
(signal 'jupyter-publisher-subscribers-had-errors errors)))
202217
nil)
203218
;; Cancel a publisher's subscription to another publisher.
204219
('(unsubscribe) '(unsubscribe))

0 commit comments

Comments
 (0)