Lisp HUG Maillist Archive

Simple trick to block Terminal popup

Hi, I noticed that this enables to make as many errors on the
Listener without going into debugger.

(setf (symbol-function 'conditions::conditions-error)
     #'(lambda (&rest l)
         (princ (car l))
         (abort)))

(princ (car l)) just prints a simple error message:

CL-USER 2 > a
The variable A is unbound.

CL-USER 3 > (/ 1 0)
Division-by-zero caused by / of (1 0).

Are there any conflicts when using this?

Does it also block all other sources of errors that may cause
the Terminal popup?

Are there better ways to do this? Is this the equivalent of
Terminal :top Abort to top level?

Peter


Re: Simple trick to block Terminal popup

Unable to parse email body. Email id is 9269

Re: Simple trick to block Terminal popup

Hi, this works:

(defun my-error-handler (&rest l)
   (princ (car l))
   (abort))

(setq *debugger-hook* 'my-error-handler)

Questions

1. Only glitch is that when dot or comma is entered on Listener
then the error is printed before prompt, but not after like
when entering unbound variable, or (/ 1 0), for example.
Why it is printed before prompt, and how to make it print after?

2. Does (abort) return to the top level as :top in Terminal would do,
cleaning up it all properly?

3. How to make my-error-handler list backtrace? I noticed that

(defun my-error-handler (&rest l)
   (princ (car l))
   (dbg::abort-to-top-level))

lists EVERY SECOND TIME error by case CL-USER 7, then case CL-USER 8,
etc.. Here are the cases:

CL-USER 7 > a
The variable A is unbound.

The next time it is

CL-USER 8 > a
The variable A is unbound.
There is no way to abort.

Error: The variable A is unbound.
   1 (continue) Try evaluating A again.
   2 Return the value of :A instead.
   3 Specify a value to use this time instead of evaluating A.
   4 Specify a value to set A to.
   5 (abort) Return to level 0.
   6 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other options

Notice that backtrace works now ok:

CL-USER 8 > :b
Call to EVAL
Call to CAPI::CAPI-TOP-LEVEL-FUNCTION
Call to CAPI::INTERACTIVE-PANE-TOP-LOOP
Call to (SUBFUNCTION MP::PROCESS-SG-FUNCTION MP::INITIALIZE-PROCESS-STACK)

4. This gives me idea to make my-error-handler *debugger-hook*
perform this way. Any pointers how to make it?

CL-USER 8 > a

Error: The variable A is unbound.
Backtrace:
Call to EVAL
Call to CAPI::CAPI-TOP-LEVEL-FUNCTION
Call to CAPI::INTERACTIVE-PANE-TOP-LOOP
Call to (SUBFUNCTION MP::PROCESS-SG-FUNCTION MP::INITIALIZE-PROCESS-STACK)

Then it does automatically the equivalent as entering :top to the
Terminal would do.

And then Listener is ready to listen again, without piling up
those debugging levels:

CL-USER 9 >

Pekka

>  >>>>> On Fri, 26 Jun 2009 08:37:31 +0300, Pekka Tolonen said:
>>
>>  Hi, I noticed that this enables to make as many errors on the
>>  Listener without going into debugger.
>>
>  > (setf (symbol-function 'conditions::conditions-error)
>>       #'(lambda (&rest l)
>>           (princ (car l))
>>           (abort)))
>  >
>>  (princ (car l)) just prints a simple error message:
>>
>>  CL-USER 2 > a
>>  The variable A is unbound.
>>
>>  CL-USER 3 > (/ 1 0)
>>  Division-by-zero caused by / of (1 0).
>>
>>  Are there any conflicts when using this?
>
>This is a bad idea for two reasons.  It will break any code that handles its
>own errors and it changes an internal undocumented function in the
>implementation.
>
>
>>  Does it also block all other sources of errors that may cause
>>  the Terminal popup?
>>
>>  Are there better ways to do this? Is this the equivalent of
>>  Terminal :top Abort to top level?
>
>Setting *debugger-hook* is a better way.
>
>__Martin


Re: Simple trick to block Terminal popup

Unable to parse email body. Email id is 9273

Re: Simple trick to block Terminal popup

Hi, this minimal debugger works neatly. Thanks!

(defun my-error-handler (&rest l)
   (let ((backtrace (with-output-to-string (stream)
                      (dbg:output-backtrace t stream))))
     (princ (car l))
     (terpri)
     (princ backtrace)
     (abort)))

(setq *debugger-hook* 'my-error-handler)

CL-USER 15 > a
The variable A is unbound.
Interpreted call to MY-ERROR-HANDLER
Call to INVOKE-DEBUGGER
Call to EVAL
Call to CAPI::CAPI-TOP-LEVEL-FUNCTION
Call to CAPI::INTERACTIVE-PANE-TOP-LOOP
Call to (SUBFUNCTION MP::PROCESS-SG-FUNCTION MP::INITIALIZE-PROCESS-STACK)

Pekka

>  >>>>> On Fri, 26 Jun 2009 16:03:35 +0300, Pekka Tolonen said:
>>
>>  Hi, this works:
>>
>  > (defun my-error-handler (&rest l)
>>     (princ (car l))
>>     (abort))
>>
>>  (setq *debugger-hook* 'my-error-handler)
>  >
>>  Questions
>>
>>  1. Only glitch is that when dot or comma is entered on Listener
>>  then the error is printed before prompt, but not after like
>>  when entering unbound variable, or (/ 1 0), for example.
>>  Why it is printed before prompt, and how to make it print after?
>
>Sorry, there is no API to change that.  The error occurs while the Listener is
>reading, which makes it print random messages before the prompt so they do not
>get mixed up with the input you have typed.
>
>
>>  2. Does (abort) return to the top level as :top in Terminal would do,
>>  cleaning up it all properly?
>
>It actually behaves like :a rather than :top, but it does clean up properly.
>Of course, if you never get into the debugger, then :top and :a are probably
>the same thing.
>
>
>>  3. How to make my-error-handler list backtrace?
>
>Call (dbg:output-backtrace t).
>
>
>>                                                  I noticed that
>>
>>  (defun my-error-handler (&rest l)
>>     (princ (car l))
>>     (dbg::abort-to-top-level))
>>
>>  lists EVERY SECOND TIME error by case CL-USER 7, then case CL-USER 8,
>>  etc..
>
>You can't expect to get sensible results by calling the internal function
>dbg::abort-to-top-level.
>
>--
>Martin Simmons
>LispWorks Ltd
>http://www.lispworks.com/


Updated at: 2020-12-10 08:40 UTC