Subject: Re: bug#76786: 31.0.50; condition-case's `debug` causes Emacs to exit when in batch mode
From: Stefan Monnier <[email-masked]>
To: [email-masked]
Date: Thu, 06 Mar 2025 13:06:54 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

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.