[hunchentoot-devel] Backtrace display

Daniel White daniel at whitehouse.id.au
Thu Sep 3 03:44:46 UTC 2009


On Wed, 2 Sep 2009 21:54:14 -0400
Jonathon McKitrick <jmckitrick at gmail.com> wrote:

> Thanks, I'll check these out.  It looks pretty weblocks-specific, but
> I assume it can be adapted to hunchentoot easily enough?  I'll just
> look for a similar method  to wrap with the AROUND method.
> 
> On Tue, Sep 1, 2009 at 2:50 PM, Leslie P. Polzer<sky at viridian-project.de> wrote:
> >
> > Jonathon McKitrick wrote:
> >> I recall some time ago, the break and backtrace capability of
> >> Hunchentoot was removed, perhaps to make it less platform dependent.
> >> But I still find myself often trying to find the origin of cryptic
> >> error messages, and adding FORMAT and BREAK statements to narrow down
> >> the problem area.  What is a good way to drop in support for, say,
> >> SBCL, so that an error will break into the debugger with a backtrace,
> >> or even dump the backtrace to the log file?
> >
> > See http://bitbucket.org/S11001001/weblocks-dev/src/tip/src/error-handler.lisp
> > and http://bitbucket.org/S11001001/weblocks-dev/src/tip/src/request-handler.lisp#cl-61
> >
> >  Leslie

For debugging purposes, I've been using the following for a while.  It
only extends Andreas' suggestion slightly by handling the IO-TIMEOUT
condition I was experiencing in SBCL.

;;; Acceptor that provides debugging from the REPL
;;; Based on an email by Andreas Fruchs:
;;; http://common-lisp.net/pipermail/tbnl-devel/2009-April/004688.html
(defclass debuggable-acceptor (acceptor)
     ()
  (:documentation "An acceptor that handles errors by invoking the
  debugger."))

(defmethod process-connection ((*acceptor* debuggable-acceptor) (socket t))
  (declare (ignore socket))
  ;; Invoke the debugger on any errors except for SB-SYS:IO-TIMEOUT.
  ;; HTTP browsers usually leave the connection open for futher requests,
  ;; and Hunchentoot respects this but sets a timeout so that old connections
  ;; are cleaned up.
  (let ((*debugging-p* t))
    (handler-case (call-next-method)
      #+sbcl (sb-sys:io-timeout (condition) (values nil condition))
      (error (condition) (invoke-debugger condition)))))

(defmethod acceptor-request-dispatcher ((*acceptor* debuggable-acceptor))
  (let ((dispatcher (call-next-method)))
    (lambda (request)
      (handler-bind ((error #'invoke-debugger))
        (funcall dispatcher request)))))

-- 
Daniel White




More information about the Tbnl-devel mailing list