minya
minya

Reputation: 325

How do I make SBCL invoke debugger on any condition/error?

For instance, when SBCL says

The value NIL is not of type CONS

I'd like to break execution and invoke the debugger at the point of error.

Right now it is bubbled up all the way to the caller (the Wookie async web server, in my case) where it is simply reported by the default error handler function. Calling (break) in the said function does invoke the debugger, but with Wookie's call stack.

Upvotes: 0

Views: 213

Answers (1)

andrew
andrew

Reputation: 2879

I may be able to help with your question. There are two possible things going on. One is that you started your event loop with

(with-event-loop (:catch-app-errors t) ...)

This essentially tells cl-async that you want it to catch any errors that are not handled and run the default event handler for them. The default error handler says "is this an actual error? of so call (error event)." This makes it so that your errors appear to be originating from within cl-async's toplevel. The purpose behind this is that you can write your own error handler to catch things as you see fit.

The second thing that may be going on is that you're using cl-async's futures, which also obfuscate errors by wrapping them in their own error handling. This makes async lexical error handling possible via the future-handler-case macro.

So if you're getting an error and you don't know where, do the following:

;; do this *before* loading cl-async-future. this turns off ALL error capturing for
;; futures, letting your errors bubble up to top level without interference
(push :future-debug *features*)

;; ... load cl-async / wookie ...

;; tell cl-async not to catch errors
(cl-async:with-event-loop (:catch-app-errors nil) ...)

Now when you get an error, it should bubble up to the REPL and you'll be able to see exactly where it came from. There are ways (using futures, at least) to get a makeshift backtrace for errors that happen deep within async functions, but that's beyond the scope of the answer and assumes that you're even using futures in the first place (although Wookie does make some use of them).

Hope that helps!

Upvotes: 1

Related Questions