GNU bug report logs - #76949
30.1; --debug-init and condition-case-unless-debug

Previous Next

Package: emacs;

Reported by: "Nussbaum Ferdinand" <ferdinand.nussbaum <at> inf.ethz.ch>

Date: Tue, 11 Mar 2025 17:20:03 UTC

Severity: normal

Found in version 30.1

To reply to this bug, email your comments to 76949 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#76949; Package emacs. (Tue, 11 Mar 2025 17:20:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Nussbaum Ferdinand" <ferdinand.nussbaum <at> inf.ethz.ch>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 11 Mar 2025 17:20:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Nussbaum  Ferdinand" <ferdinand.nussbaum <at> inf.ethz.ch>
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Cc: "me <at> bcc32.com" <me <at> bcc32.com>,
 "monnier <at> iro.umontreal.ca" <monnier <at> iro.umontreal.ca>
Subject: 30.1; --debug-init and condition-case-unless-debug
Date: Tue, 11 Mar 2025 17:13:56 +0000
[Message part 1 (text/plain, inline)]
Errors inside condition-case-unless-debug do not trigger the debugger when the
--debug-init startup option is set (and debug-on-error is not additionally and
explicitly set to a non-nil value).

This can be reproduced, for example, by adding the following to init.el:

(condition-case-unless-debug nil
    (error "error")
  (error
   (message "error caught")))

and restarting Emacs with --debug-init. In Emacs 29 this enters the debugger
(as expected), while in Emacs 30 the message "error caught" is displayed.

On a related note, the Emacs Lisp reference manual still says the following: "[...]
use the option ‘--debug-init’. This binds debug-on-error to t while loading the
init file, [...]".
(https://www.gnu.org/software/emacs/manual/html_node/elisp/Error-Debugging.html#Error-Debugging)
AFAICT this is no longer correct since the implementation uses handler-bind instead.

(Originally reported in https://github.com/syl20bnr/spacemacs/issues/16871
and https://github.com/syl20bnr/spacemacs/issues/16619#issuecomment-2708510954.)

Best,
Ferdinand
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76949; Package emacs. (Tue, 11 Mar 2025 20:43:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: "Nussbaum Ferdinand" <ferdinand.nussbaum <at> inf.ethz.ch>
Cc: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>,
 "me <at> bcc32.com" <me <at> bcc32.com>
Subject: Re: 30.1; --debug-init and condition-case-unless-debug
Date: Tue, 11 Mar 2025 16:41:42 -0400
> Errors inside condition-case-unless-debug do not trigger the debugger when the
> --debug-init startup option is set (and debug-on-error is not additionally and
> explicitly set to a non-nil value).

Indeed this is the direct consequence of:

> AFAICT this is no longer correct since the implementation uses handler-bind instead.

It seems cumbersome to fix this without re-introducing the problem that
`handler-bind` addresses, so I'm in favor of fixing the doc rather than
the code.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76949; Package emacs. (Wed, 12 Mar 2025 12:57:02 GMT) Full text and rfc822 format available.

Message #11 received at 76949 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: ferdinand.nussbaum <at> inf.ethz.ch, me <at> bcc32.com, 76949 <at> debbugs.gnu.org
Subject: Re: bug#76949: 30.1; --debug-init and condition-case-unless-debug
Date: Wed, 12 Mar 2025 14:55:43 +0200
> Cc: 76949 <at> debbugs.gnu.org, me <at> bcc32.com
> Date: Tue, 11 Mar 2025 16:41:42 -0400
> From:  Stefan Monnier via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> > Errors inside condition-case-unless-debug do not trigger the debugger when the
> > --debug-init startup option is set (and debug-on-error is not additionally and
> > explicitly set to a non-nil value).
> 
> Indeed this is the direct consequence of:
> 
> > AFAICT this is no longer correct since the implementation uses handler-bind instead.
> 
> It seems cumbersome to fix this without re-introducing the problem that
> `handler-bind` addresses, so I'm in favor of fixing the doc rather than
> the code.

Feel free to fix the documentation.  But it would be nice if we could
tell users what to use instead of condition-case-unless-debug in these
cases.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76949; Package emacs. (Thu, 13 Mar 2025 04:23:02 GMT) Full text and rfc822 format available.

Message #14 received at 76949 <at> debbugs.gnu.org (full text, mbox):

From: Aaron Zeng <me <at> bcc32.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: ferdinand.nussbaum <at> inf.ethz.ch, me <at> bcc32.com,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, 76949 <at> debbugs.gnu.org
Subject: Re: bug#76949: 30.1; --debug-init and condition-case-unless-debug
Date: Wed, 12 Mar 2025 22:24:07 -0400
With apologies to the maintainers, I accidentally replied directly 
to
Stefan rather than reply-all.  Copying in some context from our
exchange below (hand-edited from the most recent email I received 
from
Stefan):

> Aaron Zeng <me <at> bcc32.com> writes:
>
> > Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
> >
> > >> It seems cumbersome to fix this without re-introducing the 
> > >> problem that
> > >> `handler-bind` addresses, so I'm in favor of fixing the doc 
> > >> rather than
> > >> the code.
> > >
> > > I understand this to mean that we should fix the doc to 
> > > reflect that
> > > `debug-on-error` is no longer explicitly non-nil when 
> > > --debug-init is
> > > passed.
> >
> > Yes.
> >
> > > But for the other issue, I think we should still make it so 
> > > that
> > > condition-case-unless-debug works with --debug-init as 
> > > advertised (and
> > > as it did in Emacs 29).  Do you agree?
> >
> > No, for the same reason: `condition-case-unless-debug` depends 
> > on the
> > value of `debug-on-error`, not on whether the user has asked 
> > some variant of
> > "show the debugger when there's an error".
>
> condition-case-unless-debug's docstring says "it does not 
> prevent
> debugging".  It also alludes to the value of debug-on-error, but 
> this
> doc could change as well :)

Yes, but it would bring us back to the problem of how to 
implementing it
without re-introducing the problem.

> I would argue, the intention of the programmer who used
> condition-case-unless-debug likely doesn't depend on the exact 
> value
> of debug-on-error, but rather, whether or not the user "wants" 
> to
> invoke the debugger when an error is signaled inside the body.
>
> > Another way to look at it:
> >
> > `--debug-init` is there so you can debug an error that breaks 
> > your init.
> > In the case of `condition-case-unless-debug`, the error 
> > presumably
> > doesn't break your init, since it is properly caught and 
> > handled.
>
> In my experience, condition-case-unless-debug seems to be often 
> used
> to "ignore" an error but not properly catch and handle it.  For
> example in the macroexpansion of `with-demoted-errors`, or in 
> the
> original place where I found this: Spacemacs, where it is used 
> to log
> an error message somewhere and proceed with installing the rest 
> of the
> packages that are needed even if one installation fails.
>
> For me, the major concern is, code which was intended to be 
> called
> during init and used condition-case-unless-debug to make its 
> errors
> non-fatal but debuggable, has broken in a backwards-incompatible 
> way,
> and also doesn't seem to have an obvious way forwards.

There's a simple way forward: set `debug-on-error`.




This bug report was last modified 156 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.