fredokun / cl-jupyter

An enhanced interactive Shell for Common Lisp (based on the Jupyter protocol)
BSD 2-Clause "Simplified" License
199 stars 29 forks source link

Conditions issued by signal being caught by handling-errors form #13

Closed mmaul closed 8 years ago

mmaul commented 8 years ago

Some of the libraries I am using use/abuse conditions to control program flow by using signal and handler-bind. Unfortunately the condition that these libraries signal are being caught by the handling-errors form evaluator.lisp.

The snippet below will let you reproduce the behavior:

(define-condition snake-handler () ())
(handler-bind ((snake-handler (lambda (x) (format t "Bazinga:~a" x))))
(signal 'snake-handler)
(print "Doh"))

Removing the condition clause in handler case as shown below resolves the issue.

(defmacro handling-errors (&body body)
  `(handler-case
       (handler-bind
           ((simple-warning
              #'(lambda (wrn)
                  (format *error-output* "~&~A: ~%" (class-name (class-of wrn)))
                  (apply (function format) *error-output*
                         (simple-condition-format-control   wrn)
                         (simple-condition-format-arguments wrn))
                  (format *error-output* "~&")
                  (muffle-warning)))
            (warning
              #'(lambda (wrn)
                  (format *error-output* "~&~A: ~%  ~S~%"
                          (class-name (class-of wrn)) wrn)
                  (muffle-warning))))
         (progn ,@body))
       (simple-condition (err)
         (format *error-output* "~&~A: ~%" (class-name (class-of err)))
         (apply (function format) *error-output*
                (simple-condition-format-control   err)
                (simple-condition-format-arguments err))
         (format *error-output* "~&"))
       #+ignore(condition (err)
                 (format *error-output* "~&~A: ~%  ~S~%"
                         (class-name (class-of err)) err))))
fredokun commented 8 years ago

Well, of course conditions can be use for something else than error management, and since I've never done that I caught all conditions... BTW, cl-jupyter must improve its error handling (it does not follow yet completely the jupyter protocol). For the short term, I propose to only catch serious-conditions to be sure I only track errors... I hope your libraries are not subclass (then it will definitely be an abuse).

mmaul commented 8 years ago

TY latest commit fixed