all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: Philipp Stephani <p.stephani2@gmail.com>
Cc: 24618@debbugs.gnu.org
Subject: bug#24618: 26.0.50; `condition-case' doesn't allow catching all signals
Date: Mon, 13 Aug 2018 22:38:17 -0400	[thread overview]
Message-ID: <87va8dvfja.fsf@gmail.com> (raw)
In-Reply-To: <wvr4vax89ibw.fsf@a.muc.corp.google.com> (Philipp Stephani's message of "Tue, 04 Oct 2016 18:42:27 +0200")

[-- Attachment #1: Type: text/plain, Size: 623 bytes --]

tags 24618 + patch
quit

Philipp Stephani <p.stephani2@gmail.com> writes:

> Consider the following code:
>
> (condition-case err
>     (signal 'does-not-exist '(1 2))
>   (error (print err)))
>
> The signal is not caught by condition-case because it has no error
> conditions.  This makes it impossible to reliably catch all signals
> (without abusing the debugger).

Yeah, I noticed this when I started looking at fixing ert to stop
abusing the debugger like this (Bug#30745 and Bug#11218).

> I propose that an error condition of 't' in `condition-case' should be
> interpreted as 'all conditions'.

Seems easy enough:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 3127 bytes --]

From a18b70875fbcf22009e64bc9d809d1575fba3429 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Thu, 9 Aug 2018 21:26:30 -0400
Subject: [PATCH] Allow t as a catch-all condition-case handler (Bug#24618)

* src/eval.c (find_handler_clause): Accept a handler of t as always
matching.
(Fcondition_case):
* doc/lispref/control.texi (Handling Errors): Document this.
* etc/NEWS: Announce it.
---
 doc/lispref/control.texi |  7 ++++---
 etc/NEWS                 |  3 +++
 src/eval.c               | 10 ++++++----
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi
index 975ab3d075..8a6cf73af5 100644
--- a/doc/lispref/control.texi
+++ b/doc/lispref/control.texi
@@ -1878,9 +1878,10 @@ Handling Errors
 Each of the @var{handlers} is a list of the form @code{(@var{conditions}
 @var{body}@dots{})}.  Here @var{conditions} is an error condition name
 to be handled, or a list of condition names (which can include @code{debug}
-to allow the debugger to run before the handler); @var{body} is one or more
-Lisp expressions to be executed when this handler handles an error.
-Here are examples of handlers:
+to allow the debugger to run before the handler).  A condition name of
+@code{t} matches any condition.  @var{body} is one or more Lisp
+expressions to be executed when this handler handles an error.  Here
+are examples of handlers:
 
 @example
 @group
diff --git a/etc/NEWS b/etc/NEWS
index 8abbd74e05..f7de6c7295 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -836,6 +836,9 @@ specially; they are now allocated like any other pseudovector.
 * Lisp Changes in Emacs 27.1
 
 +++
+** 'condition-case' now accepts 't' to match any error symbol.
+
++++
 ** New function 'proper-list-p'.
 Given a proper list as argument, this predicate returns its length;
 otherwise, it returns nil.  'format-proper-list-p' is now an obsolete
diff --git a/src/eval.c b/src/eval.c
index 8745ba9ef9..8700f0e202 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1215,9 +1215,9 @@ DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
 where the BODY is made of Lisp expressions.
 
-A handler is applicable to an error
-if CONDITION-NAME is one of the error's condition names.
-If an error happens, the first applicable handler is run.
+A handler is applicable to an error if CONDITION-NAME is one of the
+error's condition names.  A CONDITION-NAME of t applies to any error
+symbol.  If an error happens, the first applicable handler is run.
 
 The car of a handler may be a list of condition names instead of a
 single condition name; then it handles all of them.  If the special
@@ -1854,7 +1854,9 @@ find_handler_clause (Lisp_Object handlers, Lisp_Object conditions)
   for (h = handlers; CONSP (h); h = XCDR (h))
     {
       Lisp_Object handler = XCAR (h);
-      if (!NILP (Fmemq (handler, conditions)))
+      if (!NILP (Fmemq (handler, conditions))
+          /* t is also used as a catch-all by Lisp code.  */
+          || EQ (handler, Qt))
 	return handlers;
     }
 
-- 
2.11.0


  reply	other threads:[~2018-08-14  2:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-04 16:42 bug#24618: 26.0.50; `condition-case' doesn't allow catching all signals Philipp Stephani
2018-08-14  2:38 ` Noam Postavsky [this message]
2018-09-04 23:06 ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87va8dvfja.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=24618@debbugs.gnu.org \
    --cc=p.stephani2@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.