GNU bug report logs - #76786
31.0.50; condition-case's `debug` causes Emacs to exit when in batch mode

Previous Next

Package: emacs;

Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>

Date: Thu, 6 Mar 2025 17:21:02 UTC

Severity: normal

Found in version 31.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 76786 in the body.
You can then email your comments to 76786 AT debbugs.gnu.org in the normal way.

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

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


Report forwarded to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org:
bug#76786; Package emacs. (Thu, 06 Mar 2025 17:21:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org. (Thu, 06 Mar 2025 17:21:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; condition-case's `debug` causes Emacs to exit when in
 batch mode
Date: Thu, 06 Mar 2025 12:20:28 -0500
Package: Emacs
Version: 31.0.50


    % /usr/bin/emacs -Q --batch --eval '(setq debug-on-error t)' --eval '(progn (with-demoted-errors "A %S" (error "foo")) (message "B bar"))'
    Debugger entered--Lisp error: (error "foo")
      error("foo")
      (condition-case err (error "foo") ((debug error) (message "A %S" err) nil))
      (condition-case-unless-debug err (error "foo") (error (message "A %S" err) nil))
      (with-demoted-errors "A %S" (error "foo"))
      (progn (with-demoted-errors "A %S" (error "foo")) (message "B bar"))
      eval((progn (with-demoted-errors "A %S" (error "foo")) (message "B bar")) t)
      command-line-1(("--eval" "(setq debug-on-error t)" "--eval" "(progn (with-demoted-errors \"A %S\" (error \"foo\")) (message \"B bar\"))"))
      command-line()
      normal-top-level()
    
    % 

I'm happy to see a backtrace, but I should *also* see the

    A foo
    B bar

messages that I get to see when running this code without `--batch`.


        Stefan





Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Thu, 06 Mar 2025 18:08:01 GMT) Full text and rfc822 format available.

Notification sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
bug acknowledged by developer. (Thu, 06 Mar 2025 18:08:02 GMT) Full text and rfc822 format available.

Message #10 received at 76786-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: 76786-done <at> debbugs.gnu.org
Subject: Re: bug#76786: 31.0.50; condition-case's `debug` causes Emacs to
 exit when in batch mode
Date: Thu, 06 Mar 2025 13:06:54 -0500
I pushed the fix below to `master`.
It took me a while to find the place where we short-circuited the normal
processing, to be honest (it was in `debug`).
And digging into its history doesn't completely explain why it's ever
been there, but I think it explains why it wasn't harmful back then
(`signal_or_quit` would have done the same anyway).


        Stefan


diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el
index 0ca3a0f931c..f8af6eafa32 100644
--- a/lisp/emacs-lisp/debug.el
+++ b/lisp/emacs-lisp/debug.el
@@ -253,11 +253,11 @@ debug
 		    ;; Place an extra debug-on-exit for macro's.
 		    (when (eq 'lambda (car-safe (cadr (backtrace-frame 1 base))))
 		      (backtrace-debug 2 t base))))
-                (with-current-buffer debugger-buffer
-                  (unless (derived-mode-p 'debugger-mode)
-	            (debugger-mode))
-	          (debugger-setup-buffer debugger-args)
-	          (when non-interactive-frame
+                (set-buffer debugger-buffer)
+                (unless (derived-mode-p 'debugger-mode)
+	          (debugger-mode))
+	        (debugger-setup-buffer debugger-args)
+	        (if non-interactive-frame
 		    ;; If the backtrace is long, save the beginning
 		    ;; and the end, but discard the middle.
                     (let ((inhibit-read-only t))
@@ -269,9 +269,8 @@
 		          (goto-char (point-max))
 		          (forward-line (- (/ debugger-batch-max-lines 2)))
 		          (delete-region middlestart (point)))
-		        (insert "...\n")))
-		    (message "%s" (buffer-string))
-		    (kill-emacs -1)))
+		        (insert "...\n"))
+		      (message "%s" (buffer-string)))
 	        (pop-to-buffer
 	         debugger-buffer
 	         `((display-buffer-reuse-window
@@ -300,7 +299,7 @@
 		  (message "")
 		  ;; Make sure we unbind buffer-read-only in the right buffer.
 		  (save-excursion
-		    (recursive-edit))))
+		      (recursive-edit)))))
 	    (when (and (window-live-p debugger-window)
 		       (eq (window-buffer debugger-window) debugger-buffer))
 	      ;; Record height of debugger window.





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 04 Apr 2025 11:24:17 GMT) Full text and rfc822 format available.

This bug report was last modified 134 days ago.

Previous Next


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