all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* New macro with-demoted-errors
@ 2007-07-07  6:07 Stefan Monnier
  2007-07-07 20:47 ` Richard Stallman
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2007-07-07  6:07 UTC (permalink / raw)
  To: emacs-devel


I often want to use CL's `ignore-errors' but am annoyed regularly that its
use tends to hide bugs and make them harder to track down.  

So I sugest we introduce a new macro with-demoted-errors which does the same
thing except that errors are reported (via message) to the user rather than
being silently ignored.  Also errors are not ignored if debug-on-error is
set, in the hope to make debugging easier.

The patch below includes a sample use of it in VC where it makes sure that
any error in a vc-BACKEND-registered function will not prevent the user from
visiting a file.


        Stefan


--- orig/lisp/subr.el
+++ mod/lisp/subr.el
@@ -2552,6 +2552,20 @@
 	   (or (input-pending-p)
 	       ,@body))))))
 
+(defmacro with-demoted-errors (&rest body)
+  "Run BODY and demote any errors to simple messages.
+If `debug-on-error' is non-nil, run BODY without catching its errors.
+This is to be used around code which is not expected to signal an error
+but which should be robust in the unexpected case that an error is signalled."
+  (declare (debug t) (indent 0))
+  (let ((err (make-symbol "err")))
+    `(lexical-let ((f (lambda () ,@body)))
+       (if debug-on-error
+           (funcall f)
+         (condition-case ,err
+             (funcall f)
+           (error (message "Error: %s" ,err) nil))))))
+
 (defmacro combine-after-change-calls (&rest body)
   "Execute BODY, but don't call the after-change functions till the end.
 If BODY makes changes in the buffer, they are recorded

--- orig/lisp/vc-hooks.el
+++ mod/lisp/vc-hooks.el
@@ -834,7 +834,7 @@
   (when buffer-file-name
     (vc-file-clearprops buffer-file-name)
     (cond
-     ((vc-backend buffer-file-name)
+     ((with-demoted-errors (vc-backend buffer-file-name))
       ;; Look for pending-partial-checkin file and deal with it if found.
       (vc-after-partial-checkin buffer-file-name)
       ;; Compute the state and put it in the modeline.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: New macro with-demoted-errors
  2007-07-07  6:07 New macro with-demoted-errors Stefan Monnier
@ 2007-07-07 20:47 ` Richard Stallman
  2007-07-08 14:08   ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Stallman @ 2007-07-07 20:47 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

    +    `(lexical-let ((f (lambda () ,@body)))

lexical-let is a cl macro, and I'd rather not make subr.el use them.

Perhaps we should add a way to make condition-case operate only if
(null debug-on-error).  It could use some sort of marker symbol
in the handler:

        (condition-case ,err
            (funcall f)
          ((debug error) (message "Error: %s" ,err) nil))))))

would mean to catch all errors but only if debug-on-error is nil.

That would be a lot more convenient, whether for writing the macro,
for for direct use.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: New macro with-demoted-errors
  2007-07-07 20:47 ` Richard Stallman
@ 2007-07-08 14:08   ` Stefan Monnier
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2007-07-08 14:08 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

>     +    `(lexical-let ((f (lambda () ,@body)))
> lexical-let is a cl macro, and I'd rather not make subr.el use them.

It probably breaks bootstrapping indeed.
I can make it use make-symbol, if you prefer.

> Perhaps we should add a way to make condition-case operate only if
> (null debug-on-error).  It could use some sort of marker symbol
> in the handler:

>         (condition-case ,err
>             (funcall f)
>           ((debug error) (message "Error: %s" ,err) nil))))))

> would mean to catch all errors but only if debug-on-error is nil.

But that same syntax currently means "catch `error' or `debug' signals", so
it seems a bit dangerous to change its meaning.  How 'bout

         (condition-case ,err
             (funcall f)
           (((not debug) error) (message "Error: %s" ,err) nil))))))

Still, a problem here is that it requires extending `condition-case' in the
C code and in the byte-compiler.  I'd rather just provide a new
macro condition-case-non-debug.

> That would be a lot more convenient, whether for writing the macro,
> for for direct use.

Indeed.


        Stefan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-07-08 14:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-07  6:07 New macro with-demoted-errors Stefan Monnier
2007-07-07 20:47 ` Richard Stallman
2007-07-08 14:08   ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.