Search code examples
emacscommon-lispsbclslimehunchentoot

How do I prevent slime from starting sldb on certain errors?


When serving large files from Clack/Hunchentoot with Slime connected, I sometimes see error messages like SB-IMPL::SIMPLE-STREAM-PERROR "Couldn't write to ~s"... Those are caused by the browser prematurely dropping connections (which is totally OK). The problem is that each time it happens, SLDB pops up. Which is annoying.

Is there a way I can inhibit certain errors in SLDB such as the above? I still would like to see them in an error log, but definitely not in SLDB.


Solution

  • UPDATED

    Since your system uses Hunchentoot, you could set the global variable HUNCHENTOOT:*CATCH-ERRORS-P* to T. This should guarantee that the all the conditions arising in code managed by Hunchentoot are catched by Hanchentoot itself and not passed to the debugger.

    To disable the debugger in any Common Lisp implementation (both inside a shell REPL as well as the Slime REPL inside Emacs) you could use the predefined global variable *debugger-hook*, by assigning to it a two argument function. The function will receive the condition and the current value of *debugger-hook* when it is called, and can handle the condition or return normally, and in this case the debugger is invoked. For instance, you could simply print the condition:

    * (defun my-debug(condition hook)
        (declare (ignore hook))
        (print condition)
        (abort))
    
    DEBUG-IGNORE
    * (setf *debugger-hook* #'my-debug)
    
    #<FUNCTION MY-DEBUG>
    

    This second method however cannot work when using Hunchentoot together with Slime, due to the way the two packages interact with respect to the debugging strategies.

    In this case one could adopt the solution found by Mike Ivanov, that redefines the swank-debugger-hook function before starting Swank:

    (in-package swank)
    
    (setq swank-debugger-hook-orig #'swank-debugger-hook)
    
    (defun swank-debugger-hook (condition hook)
      (etypecase condition
        (sb-int:simple-stream-error
          (progn
            (princ "*** Stream error" *error-output*)
            (abort)))
        (t (funcall swank-debugger-hook-orig condition hook))))
    
    (in-package cl-user)
    
    (swank:create-server :port 4008 :dont-close t)