emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Attaching context info to an error


From: João Távora
Subject: Re: Attaching context info to an error
Date: Tue, 26 Dec 2023 22:43:52 +0000

On Tue, Dec 26, 2023 at 8:47 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
> >> I'm playing with `handler-bind` and trying to see how we could make use
> >> of such a functionality in Emacs.
> > *loud cheers*
> [...]
> > Amongst the killer weaponry this gives us is a restart system,
> > finally.
>
> I fail to see the connection, to be honest.

The restarts themselves can be made with simply try/catch,
you're right, but automatically invoking restarts with certain
parameters based on different each error object can only be done
with  handler-bind AFAIK.

Also, for restarts to become visible/invisible according to
some information in the condition themselves (the type
of error or some other cookie) we also need handler-bind to
attach that cookie to the condition object.

Typically, a restart gives you the option to try again with
something different (not just try again as I did in this
poc), like if a network connection fails, you're given
the option to try with new credentials, or a different
protocol, etc...

> And why `handler-bind`.  IOW, why wait until the error happens before
> pushing the retry onto the list?  Why not just:
>
>     (defun pm/call-with-retry-restart (outer inner msg fn)
>       (catch outer
>         (let ((pm/restarts
>                (cons (list 'retry msg
>                            (lambda () (throw inner nil))))))
>           (while t
>             (catch inner
>               (throw outer (funcall fn)))))))

Probably, this was a thinko, or I was trying to simulate visibility
of a restart like I described above, but there are much better
ways to do that.

Anyway, as Gerd suggested, I would suggest at least supporting
EIEIO in this handler-bind. This needn't necessarily clash with
our "error symbols" if the dispatching is done via generic functions
right? The usual performance setbacks of EIEIO object shouldn't
be a problem as conditions are meant to represent exceptional
situations by definition. The counterpart to handler-bind is
handler-case btw (which is more or less our condition-case).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]